3 Replies Latest reply on Mar 27, 2009 10:38 AM by maciekpazur

    Ajax-chained selectManyListBoxes

    maciekpazur

      Hello.


      I do realize that the problem of ajax-chained selects has been discussed a number of times.
      But I tried to follow all the advice and didn't manage to make my application work.


      I am trying to implement searching UI for my application (issue management system).
      User can select some projects in selectManyListBox.


                          


      <a4j:region id="projectsPanel">
      
           <h:selectManyListbox value="#{searchIssue.selectedProjects}" size="5">
                <s:selectItems value="#{allProjects.resultList}" var="proj"
                     label="#{proj.name}" />
                <s:convertEntity />
                <a4j:support event="onchange"
                     action="#{searchIssue.projectsSelected()}" reRender="modulesPanel" />
           </h:selectManyListbox>
      
      </a4j:region>



      Then relevant modules should appear in another selectManyListbox.



      <a4j:outputPanel id="modulesPanel">
           <h:selectManyListbox value="#{searchIssue.selectedModules}" size="5">
                <s:selectItems value="#{searchIssue.availableModules}" var="module"
                     label="#{module.name}" />
                <s:convertEntity />
           </h:selectManyListbox>
      </a4j:outputPanel>



      The view is supported with a backing bean SearchIssuesAction:



      @Scope(CONVERSATION)
      @Name("searchIssue")
      @Stateful
      public class SearchIssuesAction implements SearchIssues {
      
      @In(create = true, value = "#{allProjects.resultList}")
      @SuppressWarnings(value = { "unused" })
      private List<Project> allProjects;
      
      private List<Project> selectedProjects;
      private List<Module> selectedModules;
      private List<Module> availableModules;
      
      (...)
           
      public void projectsSelected() {
           List<Module> available = new LinkedList<Module>();
           if (selectedProjects != null)
                for (Project project : selectedProjects) {
                     available.addAll(project.getModules());
                }
           availableModules = available;
      }
      
      (...getters and setter for selectedProjects, selectedModules, availableModules...)
      
      



      I run into a number of problems


      The only way to display the page, without getting an error


      Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectMany(j_id57). Found null.



      is to render the modules select only if availableModules list size is greater than 0.
      I want this select to be empty unless any projects with modules have been selected.


      If I make the above-mentioned workaround, the modules appear on the list, but
        when I submit the form it turns out that selectedModules is null.


      I would greatly appreciate any help.

        • 1. Re: Ajax-chained selectManyListBoxes
          joblini

          Hi, have you tried adding the noSelectionLabel attribute to the selectItems tag?  This attribute adds a selectItem representing no choice (null).

          • 2. Re: Ajax-chained selectManyListBoxes
            maciekpazur

            Thanks, that helped a bit:)


            No I can render the modules select at any time (no projects have to be selected).


            But



            • If I select the some items including noSelectionLabel I get



            Exception during request processing:
            Caused by javax.servlet.ServletException with message: ""
            
            (...)
            
            Caused by java.lang.NullPointerException with message: ""
            
            javax.faces.component.UISelectMany.matchValue(UISelectMany.java:508)
            javax.faces.component.UISelectMany.validateValue(UISelectMany.java:466)
            javax.faces.component.UIInput.validate(UIInput.java:875)
            javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
            (...)




            • If I select any other items I get a validation error




            • The application works only if I don't select anything in the modules select (then the selectedModules list is empty)



            Have you got any ideas?

            • 3. Re: Ajax-chained selectManyListBoxes
              maciekpazur

              OK. I added

              <begin-conversation join="true"/> 

              to the appropriate page.xml file.
              Now I don't get the validation error.


              My last problem is to detect that the noSelectionLabel has been chosen.
              When noSelectionLabel is chosen in a selectOne null is returned as select value. I haven't got the slightest idea why it is different when I use selectMany.


              Greetings.