2 Replies Latest reply on Feb 3, 2008 4:17 PM by pmuir

    ui:insert and setting values

      Simple question: I'm defining a template which I want to display one of the defined items twice. For example, here's what the template looks like:

      <ui:composition>
       <h2>Here it is the first time:</h2>
       <ui:insert name="groupA"/>
       <h2>And now we see it again:</h2>
       <ui:insert name="groupA"/>
      </ui:composition>


      And that works correctly. Next step, I would like to have different settings within the template when I run it the second time. For example:

      The file using the template:
      (Some stuff)
      
      <ui:decorate template="/my-template.xhtml">
      
       <ui:define name="groupA">
       This content shows up always!
      
       <s:div rendered="{showFirstTime}">
       This div will show only when showFirstTime is true
       </s:div>
      
       <s:div rendered="{showSecondTime}">
       This div will show only when showFirstTime is true
       </s:div>
       </ui:define>
      </ui:decorate>
      
      (some more stuff)


      Then I would like to make the template look like this:

      <ui:composition>
       <h2>Here it is the first time:</h2>
      
       <ui:insert name="groupA">
       <ui:param name="showFirstTime" value="#{true}"/>
       <ui:param name="showSecondTime" value="#{false}"/>
       </ui:insert>
      
       <ui:insert name="groupA">
       <ui:param name="showFirstTime" value="#{false}"/>
       <ui:param name="showSecondTime" value="#{true}"/>
       </ui:insert>
      
       <h2>And now we see it again:</h2>
       <ui:insert name="groupA"/>
      </ui:composition>


      But that doesn't work. The value set by ui:param doesn't show up.

      Any ideas on how to do this? I'm obviously missing something with Facelets here. Is there some tag to set a value in the page context? That seems like what I want to do, but <ui:param> (and f:param) don't do it.

      Thanks


        • 1. Re: ui:insert and setting values

          Ok, I figured out a way to do this which works nicely. I simply use:

          <c:set var="showFirstThing" value="#{true}"/>


          etc.

          It works. Is this the right way? I remember seeing somewhere that it's bad to use the http://java.sun.com/jstl/core tags within Facelets, so, for example, I never use <c:if> or those things. Is this good advice? Can anyone elaborate on this?

          • 2. Re: ui:insert and setting values
            pmuir

            This sounds like a bug in facelets to me. I suggest you ask on the facelets mailing list.