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

    Dynamically showing or hiding group of component with a4j:su

    Marc Sansa Newbie

      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
          Sergey Smirnov Master

          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
            Marc Sansa Newbie

            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}"
            reRender="ComplexConstructionDiv"/>
            </h:selectOneListbox>
            <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"/>
            </h:selectOneRadio>
            </h:panelGrid>
            </t:div>

            from faces-config.xml

            <managed-bean>
            <managed-bean-name>pcbRequestInfoBean</managed-bean-name>
            <managed-bean-class>mot.aptc.rprc.jobentry.bean.PcbRequestInfoBean</managed-bean-class>
            <managed-bean-scope>session</managed-bean-scope>
            </managed-bean>

            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;
            }
            else
            this.pcbConstructionIsComplex = true;
            }

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

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

              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...
              
              </h:panelGrid>
              </a4j:outputPanel>


              Thanks
              Mitesh

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

                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.