I have a Webapp using Primefaces 3.3.1 (runnning on Glassfish 3.0.1) in which the user can choose the desired content in a menu. Since only a part of the page is to be refreshed, I want to use partial page refreshing with AJAX. The method to store the URL is provided in the actionListener-attribute of the commandButton, whereas the id of the component which must be updated is provided in the update-attribute of the commandButton.
I'll attach my sample sourcecode first - which I got from another thread regarding PPR, but was confirmed to be working:
main.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<h:panelGroup id="content" layout="block">
<ui:include src="#{navBean.activePage}" />
</h:panelGroup>
<h:form>
<p:commandButton value="next"
actionListener="#{navBean.next}"
update=":content" />
<p:commandButton value="back"
actionListener="#{navBean.back}"
update=":content" />
</h:form>
</h:body>
</html>
NavBean
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
@ManagedBean
@SessionScoped
public class NavBean {
private String activePage = "somepage.xhtml";
public String getActivePage() {
return activePage;
}
public void setActivePage(String activePage) {
this.activePage = activePage;
}
public void next(ActionEvent e) {
this.setActivePage("someotherpage.xhtml");
}
public void back(ActionEvent e) {
this.setActivePage("somepage.xhtml");
}
}
Sample included page ("somepage.xhtml")
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h2>Just some content for testing purposes</h2>
</ui:composition>
Now, the problem is, that getActivePage
is always called before setActivePage
- which is obviously a problem because one would have to click a button twice for getting the new content.
I have a feeling that I am missing something essential here, buts earching on Google/stackoverflow did not bring any applicable results.
Update: Replacing actionListener
with action
did not work (I of course changed the input parameters of the called methods accordingly).
As erencan suggested in his comment below, I replaced the <ui:include>
with a <h:outputText>
for displaying only a string:
<h:outputText value="#{navBean.activePage}" />
Contrary of my expectations, this is working fine. So why does <h:outputText>
work, whereas <ui:include>
does not? Using the former is not an option, since I want to use JSFs templating features.