0

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>
Community
  • 1
  • 1
RaoPotla
  • 107
  • 2
  • 13
  • @BalusC, Thanks for the reply. In your mentioned link, there is no usage of JSTL. My doubt is that.. Is JSTL tags be processed while render phase in JSF or not ?. The way JSTL used in my posted question is correct or not.? – RaoPotla May 25 '15 at 05:33
  • Based on your question in its current form, I understood that the answer in this duplicate also solves the problem you're actually trying to solve. Do note that `` is also a taghandler. – BalusC May 25 '15 at 06:31
  • @BalusC, yes we can achieve what i am trying to solve as you mentioned. Some time i may need to use JSTL to render a set of fileds in a PanelGrid. Then instead of putting render condition for each field.. i can group these fields under '' and render based on render condition in 'test' attribute of ''. Since the tab handler information will not be saved in the view tree created when the first request send for the view... How JSF able to include and render only **Page1.xhtml** or **Page2.xhtml** content based on selected option in select memu. Pls. help to clarify. – RaoPotla May 25 '15 at 09:30
  • 1
    use dynamic include: – skybber May 25 '15 at 11:03
  • Are JSTL tags evaluated while render response time in JSF? Is JSTL tag information stored in JSF view(UIViewRoot)?. The way how JSTL used in my post is correct or not ?. Please help to reply if there is any thing wrong in how JSTL used in the above post. – RaoPotla May 27 '15 at 17:12

0 Answers0