JSF dynamic include using Ajax request
ajax, dynamic, include, jsf-2, primefaces
Solution
The JSTL tags as proposed in the other answer are not necessary and it is not nicely reuseable.
Here's a basic example using pure JSF (assuming that you runs Servlet 3.0 / EL 2.2, otherwise you indeed need to use `<f:setPropertyActionListener>` like as in your question):
<h:form>
<f:ajax render=":include">
<h:commandLink value="page1" action="#{bean.setPage('page1')}" />
<h:commandLink value="page2" action="#{bean.setPage('page2')}" />
<h:commandLink value="page3" action="#{bean.setPage('page3')}" />
</f:ajax>
</h:form>
<h:panelGroup id="include">
<ui:include src="#{bean.page}.xhtml" />
</h:panelGroup>
with
private String page;
@PostConstruct
public void init() {
this.page = "page1"; // Ensure that default is been set.
}
// Getter + setter.
Problem
In JSF2, is it possible to change the of value of src of ui:include dynamically using Ajax request (like for example PrimeFaces p:commandButton)? Thank you. ``` <h:form> <h:commandLink value="Display 2" action="#{fTRNav.doNav()}"> <f:setPropertyActionListener target="#{fTRNav.pageName}" value="/disp2.xhtml" /> </h:commandLink> </h:form> <ui:include src="#{fTRNav.pageName}"></ui:include> ``` That's what I have right now. Is it possible to make it Ajax (using p:commandButton)?