i have read in the link JSTL in JSF2 Facelets that JSTL tags are evaluated only during view build time and not in view render time. I have the below xhtml file which includes 2 pages. These pages are included dynamically based on selected page from the select menu. When the first request send for this page.. then the view will be created for this page but Page1.xhtml and Page2.xhtml are not included. When i select the Page1 from select menu using ajax request and render id="pageGroup"
then Page1.xhtml is included in the view and rendered. Need help how the jsf process the JSTL tag <c:if>
when the ajax request fired by selecting Page1 from select menu. Since JSF not process the section id="pageGroup"
when the Page1 is selected from the select menu.. How JSF processing the <c:if>
and building & rendering the Page1.xhtml. Please help.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head><title>JSF with JSTL</title>
<link href="../css/styles.css"
rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<div align="center">
<h:form id="testForm">
<h:panelGrid columns="2">
<h:outputLabel value="Select Page"/>
<h:selectOneMenu id="selectPageId" value="#{testBean.selectedPage}">
<f:selectItem itemLabel="Select" />
<f:selectItem itemLabel="Page 1" itemValue="page1" />
<f:selectItem itemLabel="Page 2" itemValue="page2" />
<f:ajax execute="@this" render="pageGroup" listener="#{testBean.selectPageListener}"/>
</h:selectOneMenu>
</h:panelGrid>
<h:panelGroup id="pageGroup">
<c:if test="#{testBean.renderPage1}">
<ui:include src="Page1.xhtml" />
</c:if>
<c:if test="#{testBean.renderPage2}">
<ui:include src="Page2.xhtml" />
</c:if>
</h:panelGroup>
</h:form>
</div>
</h:body>
</html>
TestBean.java
import javax.faces.event.AjaxBehaviorEvent;
public class TestBean {
private String selectedPage;
private boolean renderPage1;
private boolean renderPage2;
public String getSelectedPage() {
return selectedPage;
}
public void setSelectedPage(String selectedPage) {
this.selectedPage = selectedPage;
}
public boolean isRenderPage1() {
return renderPage1;
}
public void setRenderPage1(boolean renderPage1) {
this.renderPage1 = renderPage1;
}
public boolean isRenderPage2() {
return renderPage2;
}
public void setRenderPage2(boolean renderPage2) {
this.renderPage2 = renderPage2;
}
public void selectPageListener(AjaxBehaviorEvent event) {
renderPage1 = false;
renderPage2 = false;
if("page1".equals(selectedPage)){
renderPage1 = true;
}else if("page2".equals(selectedPage)){
renderPage2 = true;
}
}
}
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
version="2.1">
<managed-bean>
<managed-bean-name>testBean</managed-bean-name>
<managed-bean-class>com.test.TestBean</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
</faces-config>