7 Replies Latest reply on Apr 22, 2010 8:07 AM by Sunay Shah

    rich:listShuttle always returns an empty list in targetSelec

    nimo stephan Master

      I have a rich:listShuttle:

      <rich:listShuttle id="listShuttleUI" sourceValue="#{myBean.availableString}" targetSelection="#{myBean.selectedStrings}"
       var="string" >
      
      <rich:column>
       <h:outputLabel value="#{string}"/>
      </rich:column>
      
      
      </rich:listShuttle>


      My getters/setters for my targetSelection:

      private List<String> selectedStrings = new ArrayList<String>;
      public List<String> getSelectedStrings() { return selectedStrings; }
      public void setSelectedStrings(List<String> selectedStrings) { this.selectedStrings= selectedStrings; }


      The list myBean.availableString displays successfully all selectable string-values at the left side (sourceValue).

      When I pick a value, then the value is shown at the right side (targetSelection), BUT when I submit the form, the list myBean.selectedStrings is empty, even I had selected values.

      Any suggestions ???

      (I have the same scenario implemented with a rich:pickList, and it works. But I need the rich:listShuttle. As I have String-Values in my list, I do not need to declare a converter for my listShuttle.)


        • 1. Re: rich:listShuttle always returns an empty list in targetS
          Nick Belaevski Master

          Hi,

          targetSelection represents set of items selected by the user in the target (right) list but not the set of the items that target list contains. Use targetValue to get the set of the items in the target list.

          • 2. Re: rich:listShuttle always returns an empty list in targetS
            nimo stephan Master

            Hello nbelaevski,

            thank you! That was my fault. I changed it to targetValue and now it works.

            Besides, I have also successfully integrated a converter with a Entity . All works fine!

            One thing, I don t understand:

            Do you know, how can I group the items in the boxes?

            For example, I have a row containing the columns: Gender and Name.

            Now, I want to group the rows by Gender or show only the rows which gender are female.

            I have tried that with rich:column filterBy=.., but this does not work:

            <rich:listShuttle sourceValue="#{myBean.availablePersons}" targetValue="#{myBean.selectedPersons}" var="person" converter="myConverter">
            
            <rich:column filterBy="#{person.gender}" filterEvent="onkeyup">
             <f:facet name="header">
             <h:outputText value="Gender" />
             </f:facet>
             <h:outputLabel value="#{person.gender}"/>
            </rich:column>
            
            <rich:column>
             <f:facet name="header">
             <h:outputText value="Name" />
             </f:facet>
             <h:outputLabel value="#{person.name}"/>
            </rich:column>
            
            </rich:listShuttle>



            How would you do that?

            How can I do that?

            With a h:selectBox in the first row or should I integrate a rich:tree into the shuttleBox?

            I have no clue.

            • 3. Re: rich:listShuttle always returns an empty list in targetS
              Nick Belaevski Master

              Hi,

              filterBy works for rich:dataTable only. I think it's not a good idea to integrate rich:tree into listShuttle.

              You should do grouping and filtering on the server by changing sourceValue and targetValue collections respectively. You can hide/show rich:column using "rendered" attribute.

              • 4. Re: rich:listShuttle always returns an empty list in targetS
                nimo stephan Master

                hey you,

                I have done it successfully...done grouping and filtering on the server by changing sourceValue and targetValue..all works fine.

                hmm..now I have a question about rich:listShuttles sourceSelection/targetSelection-Property:

                <rich:listShuttle sourceValue="#{myBean.sourceItems}" targetValue="#{myBean.targetItems}"
                sourceSelection="#{myBean.sourceItemsSelections}" targetSelection="#{targetItemsSelections}" var="item" converter="myItemConverter">


                I can get/set all values of the source-box (left side) via 'myBean.sourceItems' and can get/set all values of the target-box (right side) via 'myBean.targetItems'. This works.

                But my sourceSelection and targetSelection does not work:

                After I pick a item from the source-box to the target-box, I would expect, that this item is stored in my sourceSelection and vice versa. Indeed, I can get all the items of a side via source/targetValue, but I need only these items which are transfered from one box to another.

                Afer submitting the form, the lists declared in sourceSelection and targetSelection are always empty, even I had selected items from one side to another. Do you know, why?

                According to the Richfaces-manual (rich:listShuttle):

                sourceSelection:Manages selection in a source list from the server side
                targetSelectin:Manages selection in a target list from the server side


                Have I anything misunderstood about the meaning of source/targetSelection?

                • 5. Re: rich:listShuttle always returns an empty list in targetS
                  Nick Belaevski Master

                  Let me explain by simple example. Please click the first item e.g. in source list then press Shift and click the last item of the list. You'll see all items in the list are now selected (they've got another background color if you not redefined skinning). Do not move them! Submit the form - you should see that sourceSelection is not empty now.

                  • 6. Re: rich:listShuttle always returns an empty list in targetS
                    nimo stephan Master

                    Hey,

                    yes..now I understand the meaning of sourceSelection/targetSelection (works such as the selection of a typical listbox).

                    I have activated the property "switchByClick="true". So sourceSelection/targetSelection was always empty :-)

                    But look at this scenario:

                    After I transfer a item from the source-box to the target-box, I want to store exactly this item in a separate list. I have integrated the a4j:support into my rich:listShuttle:

                    <rich:listShuttle sourceValue="#{myBean.availablePersons}" targetValue="#{myBean.selectedPersons}" var="person" converter="myConverter">
                    
                    <rich:column filterBy="#{person.gender}" filterEvent="onkeyup">
                     <f:facet name="header">
                     <h:outputText value="Gender" />
                     </f:facet>
                     <h:outputLabel value="#{person.gender}"/>
                    </rich:column>
                    
                    <rich:column>
                     <f:facet name="header">
                     <h:outputText value="Name" />
                     </f:facet>
                     <h:outputLabel value="#{person.name}"/>
                    </rich:column>
                    
                    <a4j:support event="onlistchanged" action="#{myBean.storeItemInList(person)}"/>
                    
                    </rich:listShuttle>




                    ..but the person in storeItemInList(person) is always null:

                    public void storeItemInList(Person person) {
                    
                    this.transferedItems.add(person);
                    
                    }


                    How can I access only these items which are
                    transfered
                    from one box to the other?

                    Should I do a typical loop of the targetList and look, which items are added or can I do it in a better way ?

                    • 7. Re: rich:listShuttle always returns an empty list in targetS
                      Sunay Shah Apprentice

                      rather then this

                       

                      <a4j:support event="onlistchanged" action="#{myBean.storeItemInList(person)}"/>
                      do like

                      <a4j:support event="onlistchanged" reRender="defaultCombo" />

                       

                      this would have the changed value

                       

                      one thing i want to ask is why you want to crate new list , you can automatically get it into the targetValue list , you need to keep listShuttle in form tag then only you list will be updated .... go through demo example given for listShuttle updating the toolbar

                       

                      Thanks

                      Sunay