title: JSF layout and templating
body: <p>I have a templating search.xhtml page to accept user's search term on the page. After the user click the "Search!" button, the result will be displayed on the same page, below the search box, as shown in the simple code below. </p>
  
  <p>search.xhtml:</p>
  
  <pre><code>&lt;ui:define name="search"&gt;
      &lt;h:form id="wordForm"&gt;
              &lt;h:inputText id="word" value="#{wordController.word}" /&gt;    
              &lt;h:commandButton id="search" value="Search!"
                  action="#{wordController.search}" /&gt;
      &lt;/h:form&gt;
      &lt;/ui:define&gt;
  
      /*** From here to display the search results!!! ***/
     &lt;ui:define name="searchResult"&gt;      
      &lt;h:outputText value="Search Results:"/&gt;
      &lt;c:forEach items="#{wordController.wordInfoList}" var="wordInfo"&gt;
  
          &lt;h:outputText value="#{wordInfo.display}"
              rendered="#{not empty wordInfo.display}" /&gt; 
           &lt;ui:repeat value="#{wordInfo.relatedWords}" var="relatedInfo"&gt;
              &lt;h:outputLink value="index.xhtml"&gt;
                &lt;h:outputText value="#{relatedInfo}" /&gt;
                &lt;f:param name="relatedWord" value="#{relatedInfo}" /&gt;
              &lt;/h:outputLink&gt;
           &lt;/ui:repeat&gt;
      &lt;/c:forEach&gt;
  
  /*Edit: Add a f:medatadata tag to accept the parameter "relatedWord" */
      &lt;f:metadata&gt;
              &lt;f:viewParam id="related" name="relatedWord"
                  value="#{wordController.word}" /&gt;
              &lt;f:viewAction action="#{wordController.info()}" /&gt;
      &lt;/f:metadata&gt; 
  &lt;/ui:define&gt;
  </code></pre>
  
  <p>The layout.xhtml inserts the search.xhtml to the page.</p>
  
  <p>layout.xhtml:</p>
  
  <pre><code> &lt;ui:fragment rendered="#{not empty wordController.word}"&gt;
          &lt;div id="searchResult"&gt;
              &lt;ui:insert name="searchResult"&gt;                 
              &lt;/ui:insert&gt;
          &lt;/div&gt;
  &lt;/ui:fragment&gt;
  </code></pre>
  
  <p>The problem is that, when the user visits the page, even before he clicks the "Search!" button, the search results will be always displayed together with teh search box, although the search result will be empty, except that the string "Search results: " is not empty.</p>
  
  <p>How can I modify this so that before user performs a search, it will only display the search box. and only display the search results together with the search box after the user clicks the search button. </p>
  
  <p>Thank you.</p>