7 Replies Latest reply on Nov 14, 2007 5:43 AM by Grzegorz Lesiak

    Dynamic component hiding question

    Grzegorz Lesiak Newbie

      Hi i am trying to do something that follows:

      There should be one selectOneMenu and two inputText fields
      If you select one option from selectOneMenu only one from above inputTexts should be visible/rendered. If you choose another option, another component should be visible. but other should be hidden. How to achieve this.

      I've done a form with those components and bind them to jsf bean properties, but when i try to setRendered( false ) on inputText with a4j:support reRender with id of this inputText it don't get hidden.

      Where is my mistake ?
      Please help me

        • 1. Re: Dynamic component hiding question
          Dmitry Demyankov Novice

          Can you post your code snippet here?

          I think you should try putting inputText inside panel and reRender that panel.

          • 2. Re: Dynamic component hiding question
            Grzegorz Lesiak Newbie

            i declare inputText components in my jsf bean

            private HtmlInputText companyInput;
            private HtmlInputText personInput;

            .. and initialize it
            companyInput = new HtmlInputText();
            companyInput.setValue( "" );
            companyInput.setRendered( false );

            personInput = new HtmlInputText();
            personInput.setValue( "" );
            personInput.setRendered( false );

            .. then bind in jsf page
            <h:inputText id="companyInput" binding="#{training.companyInput}" >
            <h:inputText id="personInput" binding="#{training.personInput}" >

            .. of course bean training is declared if faces-config

            <managed-bean>
            <managed-bean-class>beans.TrainingBean</managed-bean-class>
            <managed-bean-name>training</managed-bean-name>
            <managed-bean-scope>session</managed-bean-scope>
            </managed-bean>

            .. and richfaces elements on selectOneMenu...

            <h:selectOneMenu id="trainingType" value="#{training.trainingType}" >
            <a4j:support event="onchange" reRender="companyInput,personInput" actionListener="#{training.updateView}" immediate="true" />
            <f:selectItem itemValue="one" itemLabel="Option one />
            <f:selectItem itemValue="two" itemLabel="Option two" />
            </h:selectOneMenu>

            and in updateView() i would like to do something like

            getCompanyInput().setRendered( true );

            so after reRendering of companyInput the component wil be visible


            • 3. Re: Dynamic component hiding question
              Grzegorz Lesiak Newbie

               

              "dmitry.demyankov" wrote:

              I think you should try putting inputText inside panel and reRender that panel.


              I've tryied to do so but with no success.

              • 4. Re: Dynamic component hiding question
                Ilya Shaikovsky Master

                 

                "progzmaster" wrote:
                "dmitry.demyankov" wrote:

                I think you should try putting inputText inside panel and reRender that panel.


                I've tryied to do so but with no success.


                This should work. Paste latest snippet you've used please.

                • 5. Re: Dynamic component hiding question
                  Grzegorz Lesiak Newbie

                   

                  "ilya_shaikovsky" wrote:

                  This should work. Paste latest snippet you've used please.


                  Ok i have figured out the problem.
                  When HtmlSelectOneMenu have immediate attribute set to true everything is ok because i have no validation on form components.

                  When I add some validation for example required="true"
                  everything breaks because a4j:support actionListener
                  is not called before process validation phase.

                  If I add immediate="true" to a4j:support
                  then actionListener is called but I don't get
                  valid value of selectOneMenu.

                  What should I do ?

                  • 6. Re: Dynamic component hiding question
                    Ilya Shaikovsky Master

                    you should wrap to a4j:region the component that should be processed without another components validation. immediate is unnesessary in this case.

                    • 7. Re: Dynamic component hiding question
                      Grzegorz Lesiak Newbie

                       

                      "ilya_shaikovsky" wrote:
                      you should wrap to a4j:region the component that should be processed without another components validation. immediate is unnesessary in this case.


                      Thank you very much. It works !!!