9 Replies Latest reply on Dec 31, 2007 11:19 AM by Kumar Kavi

    Conditional Rendering of a component

    Kumar Kavi Newbie

      Hi,
      I'm trying to conditionally render a text-field. I have a dropdown and depending on the selection I want to show or hide the textfield. The textfield is showing/hiding properly. But the problem I have is, the value entered on the textfield is not posted to the backing bean.

      <h:form>
       <h:selectOneMenu id="searchBy" value="#{employeeSearchBean.searchBy}">
       <f:selectItem itemValue="" itemLabel="-Select--"/>
       <f:selectItem itemValue="item1" itemLabel="Item1"/>
       <f:selectItem itemValue="item2" itemLabel="Item2"/>
       <a4j:support id="test2" reRender="nameOption" event="onchange" />
       </h:selectOneMenu>
       <a4j:outputPanel id="nameOption">
       <h:inputText value="#{employeeSearchBean.field1}" id="employeeField1" rendered="#{not empty employeeSearchBean.searchBy}" />
       </a4j:outputPanel>
       <br/>
       <h:commandButton id="submitSearch" value="Search" action="#{employeeSearchBean.search}"/>
      </h:form>


      What I read from the documentation is, the text field is not in the dom tree when first loaded, so the value is not updated to the backing bean. I know this is a common requirement, but not sure how to implement it. I tried using layout="none" option for a4j:outputPanel, but no use. If anybody has faced a similar situation and found a solution, I appreciate your answer.

      Thanks,
      Kumar