3 Replies Latest reply on Mar 5, 2009 9:51 AM by Alan Gross

    Multiple Comboboxes reRendered by AJAX? valueChangeListener?

    Alan Gross Newbie

      Hello Forum
      I'm trying to setup a form containing multiple comboboxes. I want to display first just one combobox. When the user selects a value I want to AJAX reRender the next combobox. This combox should now contain a list of values (selectItems) depending on the value selected in the first comboBox.

      When the user is changing the value of the first combobox the value of the second combobox should be reset.

      As mentioned I would like to do this without refreshing the whole page (AJAX). I can't get it to work properly. Tryed to use a valueChangeListener, but I'm not sure if the valueChangeListener is working with AJAX or only with a submit of the whole form.

      Maybe someone has an example or a hint how to achieve this functionality.

      Thank you very much!
      Rgds
      Alan

        • 1. Re: Multiple Comboboxes reRendered by AJAX? valueChangeListe
          Roland Schöler Newbie

          Hi Alan, I'm sure that you have looked at the demo for rich:comboBox...8-}

          This is an example, which works for me, by AJAX and onselect:

          <rich:comboBox id="idList" value="#{mappingHandler.selectedIdentifier}" suggestionValues="#{mappingHandler.allIdentifiers}"
           directInputSuggestions="true" defaultLabel="#{msgs.mapping_combo_default}">
           <a4j:support event="onselect" reRender="YOUR IDs" ajaxSingle="true" />
           </rich:comboBox>


          My observations:
          ValueChangeListener needs submit
          PropertyActionListener works also with AJAX - I use this often inside a4j:commandlink

          One remark:
          If you have elements, which are not AJAX-able, or doesn't render correctly - just try a4j:outputPanel around
          <a4j:outputPanel id="YOUR ID" layout="none">


          With the example above I've dynamically reloaded a rich:datatable - therefore I'm sure that this could also be done with a second rich:comboBox

          regards
          rschoeler

          • 2. Re: Multiple Comboboxes reRendered by AJAX? valueChangeListe
            Alan Gross Newbie

            Hi!

            Thank you for the reply. My problem was that I try to implement all the business logic in the backing bean and not in the POJO (data model).

            When reRendering a partial part of the page all getters of the fields in this partial part are executed. I only had getters of the POJO available, not of the bean (e.g. bean.record.name). I got it now to work. I just added a dummy-label to the form. This label is referencing to a entity of the backing bean. In the getter of this dummy-label I implemented the logic to reload the lists and resetting field if necessary. It works pretty charming even if I have the feeling that it could be done better.

            Regards
            Alan

            • 3. Re: Multiple Comboboxes reRendered by AJAX? valueChangeListe
              Alan Gross Newbie

              I used the combobox completly the wrong way round. the rich:comboBox is not meant to be used for selections..

              the suggestionBox is the right component to achieve this functionality..