4 Replies Latest reply on Aug 23, 2007 5:05 PM by sansaric

    Dynamically showing or hiding group of component with a4j:su


      I am trying to dynamically show or hide a group of faces components when a onchange event occurs on a <h:selectOneListbox> component that has a4j:support attached to it. I set the rendered property of the group of components I want to show or hide to true or false depending on the value of the select component in the method defined in the a4j:support actionListener and also specify the name of all components to be shown or hidden in the a4j:support rerender property. However, the component showing/hiding is not working. Any advice on how to resolve this issue would be greatly appreciated.
      Thx in advance for your help

        • 1. Re: Dynamically showing or hiding group of component with a4

          Yes, this is a JSF trap here that is not obvious. I told about it many times. The rendered (enabled, non-readonly) condition should be true at the beginning of the second phase to have the component (and its hierarchy) processed. To make components shown, it is enough to have those condition true at the beginning of the sixth phase.
          What you need to check is EL you use in the 'rendered' attribute. If it based on the request scope bean, ask your self where you set it to true. If it is after second phase, consider to use a4j:keepAlive or bean with scope more than request.

          If you still have a problem, post the code snippet.

          • 2. Re: Dynamically showing or hiding group of component with a4

            Thanks for the quick response. I was not able to dynamically show/hide a group of component as explained in the original post. Below are the code snippets you requested. and hopefully you can help shed some light.
            Thanks again for your help

            Code Snippets:

            from jsp page:

            <h:outputText value="Board Construction Method:"/>
            <h:message for="BoardConstructionMethod" styleClass="ErrorMessage" showSummary="true" showDetail="false"/>
            <h:selectOneListbox id="BoardConstructionMethod" required="true" value="#{pcbRequestInfoBean.pcb_Construct_Method}" size="1" style="background-color: #FFFFCC" immediate="true">
            <f:selectItem id="BoardConstructionMethod1" itemLabel="Select Construction" itemValue=""/>
            <f:selectItems id="BoardConstructionOptionsFromDB" value="#{pcbJobInfoHandler.pcbConstructionNames}"/>
            <a4j:support event="onchange" immediate="true" actionListener="#{pcbRequestInfoBean.updatePcbConstructionDependencies}"
            <t:div id="ComplexConstructionDiv" rendered="#{pcbRequestInfoBean.pcbConstructionIsComplex}">
            <h:panelGrid columns="8">
            <h:outputText escape="false" value="<font class=RequiredField>*Lamination Detail:"/>
            <h:message for="LaminationDetail" styleClass="ErrorMessage" showSummary="true" showDetail="false"/>
            <h:selectOneRadio id="LaminationDetail" value="#{pcbRequestInfoBean.lamination_Detail}" required="true" >
            <f:selectItem itemValue="Refer To Fab Drawing" id="LaminationDetail1" itemLabel="Refer To Fab Drawing"/>
            <f:selectItem itemValue="Specified In Special Instructions" id="LaminationDetail2" itemLabel="Specified In Special Instructions"/>
            <f:selectItem itemValue="Unspecified" id="LaminationDetail3" itemLabel="Unspecified"/>

            from faces-config.xml


            from session scope managed bean pcbRequestInfoBean:
            private String pcb_Construct_Method;
            boolean pcbConstructionIsComplex;

            //Get pcb_Construct_Method property
            public String getPcb_Construct_Method() {
            return pcb_Construct_Method;

            //Set pcb_Construct_Method property
            public void setPcb_Construct_Method(String pcb_Construct_Method) {
            if (pcb_Construct_Method != null) {
            this.pcb_Construct_Method = pcb_Construct_Method;

            //Get pcbConstructionIsComplex property
            public boolean getPcbConstructionIsComplex() {
            System.out.println("Executing getPcbConstructionIsComplex.... " + this.pcbConstructionIsComplex);
            return pcbConstructionIsComplex;

            //Set pcbConstructionIsComplex property
            public void setPcbConstructionIsComplex() {
            if (this.pcb_Construct_Method != null &&
            (this.pcb_Construct_Method.equalsIgnoreCase("Single-Sided") ||
            this.pcb_Construct_Method.equalsIgnoreCase("Double-Sided"))) {
            this.pcbConstructionIsComplex = false;
            this.pcbConstructionIsComplex = true;

            public void updatePcbConstructionDependencies(ActionEvent event) throws Exception {
            FacesContext context = FacesContext.getCurrentInstance();
            UIViewRoot root = context.getViewRoot();
            UISelectOne selectComp = (UISelectOne) root.findComponent("BoardConstructionMethod");

            • 3. Re: Dynamically showing or hiding group of component with a4

              please use following coding style might helps u..

              if still didnt work please remove immediate="true" from a4j:support and then try

              <a4j:support reRender="test" .../>
              <a4j:outputPanel id="test" ..... >
              <h:panelGrid render="[condition]">
              All Comonents to be displayed...


              • 4. Re: Dynamically showing or hiding group of component with a4

                Thank you both SergeySmirnov and Mitesh for helping me resolve this issue.
                Mitech's suggestions work well. I left the immediate="true" in the a4j:support, otherwise I get a validation error which I don't want.