6 Replies Latest reply on Apr 5, 2007 10:08 AM by ilya_shaikovsky

    question

    adrian.iacob

      for this example
      http://livedemo.exadel.com/a4j-dropDownBoxes/

      I want to have a dynamic number of dropDownBoxes (not only the values inside a dropDownBox).
      The user should see only one dropDownBox and after he selects something the second should appear and so on.

      something like adding another

      <h:selectOneMenu id="selectOneCar"
       value="#{carBean.currentCar}">
       <f:selectItems
       value="#{carBean.carList}" />
      </h:selectOneMenu>
      




      Can this be done?



        • 1. Re: question

          Conditionally render the other components using the rendered property, I've just set the second combo to show when the first's value is set to not-null. Then add the <a4j:support> and tell it which event to trap and which control you wish to reRender.

          This is the basics, you should read the docs for more info and options.

          <h:selectOneMenu id="selectOneCar" value="#{carBean.currentCar}">
           <f:selectItems value="#{carBean.carList}" />
           <a4j:support event="onchange" reRender="selectAnotherThing"/>
          </h:selectOneMenu>
          
          <h:selectOneMenu id="selectAnotherThing" value="#{carBean.otherThing}" rendered="#{carBean.currentCar != null}">
           <f:selectItems value="#{carBean.otherThings}" />
          </h:selectOneMenu>
          


          HTH.

          Mike.

          • 2. Re: question
            adrian.iacob

            The problem here is that I don't know whether I have one selectOneMenu or 10 selectOneMenu .

            let me give you an example of what I have in my head instead of carBean I will call controllerBean that has another bean calling it genericBean, This genericBean can be for example an Event bean (that has let us say 3 combo - year, month, day) or it can be a Computer bean (that has 5 combo - cpu, motherboard, optical, monitor, hard) (please remember this is an example, ignore the fact that hard, optical or motherboard are not really linked together)
            and you would hard code like this

            <h:selectOneMenu id="selectFirstProperty" value="#{controllerBean.genericBean.year}">
             <f:selectItems value="#{controllerBean.genericBean.yearList}" />
             <a4j:support event="onchange" reRender="selectSecondThing"/>
            </h:selectOneMenu>
            
            <h:selectOneMenu id="selectSecondProperty" value="#{controllerBean.genericBean.month}">
             <f:selectItems value="#{controllerBean.genericBean.monthList}" rendered="#{controllerBean.genericBean.year != null}/>
             <a4j:support event="onchange" reRender="selectThirdThing"/>
            </h:selectOneMenu>
            
            <h:selectOneMenu id="selectThirdProperty" value="#{controllerBean.genericBean.day}">
             <f:selectItems value="#{controllerBean.genericBean.dayList}" rendered="#{controllerBean.genericBean.month != null}/>
            </h:selectOneMenu>
            


            and the same would repeat itself for the Computer Bean.
            I have the list of properties for Event of Computer that would be ["year","month","day"] and ["cpu","motherboard","optical","monitor","hard"]

            and I am thinking of something like
            value="#{controllerBean.genericBean[property]}" and rendered="#{controllerBean.genericBean[previousProperty]"
            

            somehow on a loop :D

            • 3. Re: question
              ilya_shaikovsky

              Use select controls inside repeats and point its values to your model bean.

              And, Guys, also do not remember that you must reRender wrapper components but not a component that influenced by rendered attribute

              • 4. Re: question

                 

                "ilya_shaikovsky" wrote:
                And, Guys, also do not remember that you must <b>reRender</b> wrapper components but not a component that influenced by <b>rendered</b> attribute


                Oops, forgot about that, my bad.

                • 5. Re: question
                  adrian.iacob

                  please give more details... I know what I want, I hope I was clear. I don't know how !... So please give more details what repeats (I would love a fully functional example!)

                  • 6. Re: question
                    ilya_shaikovsky

                    download full examples at examples page http://labs.jboss.com/portal/jbossajax4jsf/demo/index.html