2 Replies Latest reply on Sep 9, 2009 3:17 PM by Alex Cougarman

    Hide/show rich:panels based on h:selectOneMenu value

    Alex Cougarman Apprentice

      I've spent a few hours spinning my wheels on this: I need to change the rendered property on some rich:panel controls based on what the user chooses from an h:selectOneMenu dropdown. Here are the tags:

      <a4j:outputPanel>
      <h:selectOneMenu value="#{webencode.requestType}"
       id="rdoRequestType">
       <f:selectItem itemValue="program" itemLabel="Series or Program"/>
       <f:selectItem itemValue="special" itemLabel="Special"/>
       <a4j:support ajaxSingle="true" event="onchange"
       reRender="program" immediate="true"/>
      </h:selectOneMenu></a4j:outputPanel>
      
      <a4j:outputPanel id="program">
       <rich:panel rendered="#{webencode.checkRequestType('program')}">
       program
       </rich:panel>
       <rich:panel rendered="#{webencode.checkRequestType('special')}">
       special
       </rich:panel>
      </a4j:outputPanel>


      The code for the checkRequestType() method is this:

      public Boolean checkRequestType(String requestType){
       return (this.requestType.equalsIgnoreCase(requestType)) ? true : false;
      }


      It's there to do a string comparison. This code doesn't work -- nothing changes on the page. Help! Thanks.

        • 1. Re: Hide/show rich:panels based on h:selectOneMenu value
          Nick Belaevski Master

          Hi,

          1. Using immediate="true" presumes that model (bean properties values) are not updated

          2. Plain JSF doesn't support such type of expressions:

          #{webencode.checkRequestType('program')}
          - are you using JBoss EL extensions?

          3. Bean should have scope that is spanning several requests, e.g. session or conversation.

          • 2. Re: Hide/show rich:panels based on h:selectOneMenu value
            Alex Cougarman Apprentice

            Thanks, nbelaevski. Yes, this is using JBoss. I took the immediate="true" and it seems to be working; I also changed the control to a radio button set and used onclick as the event trigger -- onchange doesn't work for radio buttons, only dropdown boxes:

            <a4j:outputPanel>
            <h:selectOneRadio value="#{webencode.requestType}"
             id="rdoRequestType" styleClass="radio" layout="pageDirection" >
             <f:selectItem itemValue="program" itemLabel="Series or Program"/>
             <f:selectItem itemValue="special" itemLabel="Special"/>
             <a4j:support ajaxSingle="true" event="onclick" reRender="program"/>
            </h:selectOneRadio></a4j:outputPanel>
            
            <a4j:outputPanel id="program">
             <rich:panel rendered="#{webencode.checkRequestType('program')}">
             program
             </rich:panel>
             <rich:panel rendered="#{webencode.checkRequestType('special')}">
             special
             </rich:panel>
            </a4j:outputPanel>