I try to update a part of the page on button click. Right now, I have the following :
template.xhtml
<h:form prependId="false">
<h:commandButton value="NEWS" action="news">
<f:ajax render="newsContent"></f:ajax>
</h:commandButton>
<h:panelGroup layout="block" id="newsContent">
<ui:insert name="newsContent">
<ui:include src="/WEB-INF/partials/news/news.xhtml"/>
</ui:insert>
</h:panelGroup>
</h:form>
/WEB-INF/partials/news/news.xhtml
<h:commandLink action="newsdetails">
<f:ajax render="newsContent" />
</h:commandLlink>
newsdetails.xhtml
<h:commandButton value="INDEX" action="index">
<f:ajax render="newsContent" />
</h:commandButton>
Right now its working fine, but if I replace the <h:commandbutton>
with something like
<p:commandButton value="INDEX" action="index" update="newsContent"/>
Then the content is updated but the page is refreshed. Any thoughts what I am doing wrong here?
I solved it finally.
I used an actionListener on my Button.
The source of the include is now read from a Bean:
And the getter for the page looks something like:
On Pageload the currentObject is still null so the news.xhtml is shown. After the click the current is set to an Object and the page is updated to the details page. All without a reload of the page.
You are not calling any valid ajax action:
remove
action="index"
to avoid reloading the index page.