0 Replies Latest reply on Jul 21, 2011 5:32 AM by tanya_mk

    Conditionally Adding Components

    tanya_mk

      Hi all,

       

      I am trying to migrate an existing project that uses RichFaces 3.3 to use RichFaces 4.0. I faced the following problem. I want to do something like this:

       

      <h:form>

        <rich:panel>

           <c:if test="${object.data['key'] == 1}">

                <a4j:outputPanel>

                     <ui:include src="/WEB-INF/html/sectionDocument1.xhtml">

                          <ui:param name="refresh" value="sectionTree, sectionInformationPanel"/>

                          <ui:param name="thisPage" value="sections"/>

                     </ui:include>

                 </a4j:outputPanel>

           </c:if>

           <c:if test="${object.data['key'] == 2}">

                <a4j:outputPanel>

                     <ui:include src="/WEB-INF/html/sectionDocument2.xhtml">

                          <ui:param name="refresh" value="sectionTree, sectionInformationPanel"/>

                          <ui:param name="thisPage" value="sections"/>

                     </ui:include>

                 </a4j:outputPanel>

           </c:if>

        </rich:panel>

      </h:form>

       

      I want to include sectionDocument1.xhtml or sectionDocument2.xhtml according to the value of object.data['key']. The correct xhtml gets included, but the <h:form> does not work correctly. I read that it is not good idea to use <c:if> tag when working with JSF 2.0. What I found was that it should be used rendered attribute instead. However,  sectionDocument1.xhtml and sectionDocument2.xhtml have a common template. When I tried to use the rendered attribute, I had problems because the template xhtml got included twice, so I had duplication on the components ids.

       

      Does anyone know what to use instead of the <c:if> to add components conditionally?

       

      Thanks in advance!