3 Replies Latest reply on Jan 22, 2011 5:04 AM by armahdi

    selectmanyListBox : how to bind with resultlist

    armahdi

      Hello All!


      I need some help with h:selectmanyListBox.


      I need to create switchlists (Two lists and you port some elements of one list into other.) Im one list I am binding  it with a list in the entity it self, so I dont have any problems in that list, In the second list I want to list some text field of another entity in a resultlist.
      forexample : I have a list of employees in one department (that would be my list 1) the second list will be retrieved from Database as list of employees and I want to list all the names and a user can add employees in the list of employees in the department (my list1) from the list of all employees(list2) and then ofcourse persist it.


      this is what I hvae gotten so far:




      <h:form id="form1">
               
                  <h:selectManyListbox value="#{switchList.list1}" > 
                      <f:selectItems value="#{department.employees}" /> //department has a list of Employees
                  </h:selectManyListbox>
                  <h:panelGroup id="buttonGroup" >
                      <h:commandButton value="&gt;&gt;" actionListener="#{switchList.move1to2}"  />
                      <h:commandButton value="&lt;&lt;" actionListener="#{switchList.move2to1}"  />
                  </h:panelGroup>
                  <h:selectManyListbox id="employeeList"  value="#{employeeQuery.resultList}" var="question">
                      <f:selectItems value="#{employee.employeeName}"/>// ? this does not work
                  </h:selectManyListbox>
                  <br/>
                      <h:commandButton value="reload" type="submit"/>
                  <h:messages/>
              </h:form>



      the first list renders fine but when I add the second list with employeeQuery.resultlist its throws an exception:
      Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectMany(employeeList). Found null.



      I would really appreciate some help. I am really not sure how to get the selectManyListBox to work with a entityQuery object witha  resultList.


      Thanks
      Syed.

        • 1. Re: selectmanyListBox : how to bind with resultlist
          armahdi
          Note:
          var=question is actually  var=employee

          .. Does var work here?> its not giving me errors yet..



          ok i did try one more thing, i accidentally gave a value=something.name



          when something didnt really exist (there was no component with @Name with something as value) and it gave me the same exact error...

          So i know that some how employeeQuery is null I think. how can be as employeeQuery is being used in its own CRUD page where I can add employees and delete employees as well. I was hoping that when you do @Name(employeeQuery)
          , you should be able to access that component.. Is that not true??

          • 2. Re: selectmanyListBox : how to bind with resultlist
            armahdi

            ok Sorry for one thing: The first selectManyListBox doesnt work either. Now i need to know how to fill them both. It wasnt coming actually i thought that it will when I fill it.


            so my first list looks like this now:



             <h:selectManyListbox id="BTypelist" value="#{department.employees}" var ="employee">
                            <f:selectItems  value="#{employees.name}" />
                        </h:selectManyListbox>




            I want to list all the employee names in that department. How can i accomplish that??


            please help!!


            Thanks

            • 3. Re: selectmanyListBox : how to bind with resultlist
              armahdi

              Ok I did accomplish something:


              I made a transient linkedhashmap in the department class and in the getter of this Map i filled it out with


              employee.getName()as key , employee as value




              and I attached Map with the list component:


              <h:selectManyListbox id="BTypelist" value="#{switchList.list1}" >
                              <f:selectItems  value="#{department.employeesNames}" />
                          </h:selectManyListbox>
              




              I Now i need to link EmployeeQuery.resultlist with the second List. Does any one know how to do that. Or if i need to make a Map where can i make it and then how to refer it.


              Thanks.
              Syed