4 Replies Latest reply on Mar 7, 2012 3:19 AM by pczekaj

    RF 4.2 - pickList doesn't use value attribute

    pczekaj

      I'm in the middle of migrating application from RF 3 (JBoss 4.2.3) to RF 4.2.0.Final (JBoss 7.1.0). In RF 3.3 I'm using rich:listShuttle component which is missing from RF 4.2 but rich:pickList seems to be it's replacement. Similiar like in Showcase application I'm passing two collections to pickList: one via value attribute, another one via f:selectItems. My problem is that even if I will pass non empty collection to value attribute nothing is displayed on the right (elements passed by f:selectItems are corectly displayed on the left, if I will swap collection passed via value with the one passed via selectItems other collection is visible on the left so I'm sure I didn't pass empty collection). I'm not sure if it's feature or bug, in case if it's a bug below is a way how to reproduce it it in final versions of JBoss 7.0.2 or JBoss 7.1.0.

       

      Download showcase application tagged for release 4.2.0. Add to class org.richfaces.demo.lists.ListSelectBean following code:

       

          @PostConstruct
          public void init() {
              selectedCapitals = new ArrayList<Capital>();
              Capital c = new Capital();
              c.setState("Alabama2");
              c.setName("Montgomery2");
              c.setTimeZone("GMT-6");
              selectedCapitals.add(c);
          }
      

       

      To see error open web browser and navigate to component pickList sample (http://localhost:8080/showcase/richfaces/component-sample.jsf?demo=pickList), for me expected behaviour would be to see Montgomery2 on the right part of pickList component but it will be empty.

        • 1. Re: RF 4.2 - pickList doesn't use value attribute
          iabughosh

          hello Piotr,

          relax Piotr, it is not a bug , I'll explain in details :

          if you have this .xhtml code:

           

          <rich:pickList id="yourList"

                              value="#{yourBean.selectedItems}"

                              listHeight="120px"

                              listWidth="100px">

            <f:selectItems value="#{yourBean.availableItems}"

                                 var="item"

                                 itemLabel="#{item.name}"

                                 itemValue="#{item.id}"/>

          </rich:pickList>

           

          then the value attribute in the rich:pickList needs to be a collection of primitive type or String (ex:List<String>, List<Integer>), and itemValue attr at f:selectItems needs to be of a type String, int (as pickList value type).

           

          RichFaces show case was able to set List<CustomObjects> in the value attribute because they were using FacesConverter named "CapitalsConverter".

           

          regards.

          • 2. Re: RF 4.2 - pickList doesn't use value attribute
            pczekaj

            Thanks for response but even for strings pickList doesn't work as I would expect. Below image shows how page looks like in browser when first loaded, looking at init method it should show "Item 4" and "Item 5" on the right.

             

            pickListProblem.png

             

            Bean code:

             

            package example;
            
            import java.io.Serializable;
            import java.util.ArrayList;
            import java.util.List;
            
            import javax.annotation.PostConstruct;
            import javax.ejb.Stateful;
            import javax.enterprise.context.SessionScoped;
            import javax.inject.Named;
            
            @Named
            @SessionScoped
            @Stateful
            public class PickList implements Serializable {
                      private List<String> freeItems = new ArrayList<String>();
                      private List<String> selectedItems = new ArrayList<String>();
              
                      @PostConstruct
                      public void init() {
                                freeItems.add("Item 1");
                                freeItems.add("Item 2");
                                freeItems.add("Item 3");
                                selectedItems.add("Item 4");
                                selectedItems.add("Item 5");
                      }
              
                      public String save() {
                                System.err.println(selectedItems);
                                return null;
                      }
              
                      public List<String> getFreeItems() {
                                return freeItems;
                      }
                      public void setFreeItems(List<String> freeItems) {
                                this.freeItems = freeItems;
                      }
                      public List<String> getSelectedItems() {
                                return selectedItems;
                      }
                      public void setSelectedItems(List<String> selectedItems) {
                                this.selectedItems = selectedItems;
                      }
            }
            
            

             

            Facelets:

             

            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html xmlns="http://www.w3.org/1999/xhtml"
                  xmlns:ui="http://java.sun.com/jsf/facelets"
                  xmlns:h="http://java.sun.com/jsf/html"
                  xmlns:f="http://java.sun.com/jsf/core"     
                  xmlns:a="http://richfaces.org/a4j"  
                  xmlns:c="http://java.sun.com/jsp/jstl/core"
                  xmlns:rich="http://richfaces.org/rich">
                      <h:head></h:head>
                      <h:body>      
                                <h:form>
                                          <rich:messages />
                                          <rich:pickList 
                                                    value="#{pickList.selectedItems}" 
                                                    var="item"
                                                    orderable="true">
                                                    <rich:column>
                                                              <h:outputText value="#{item}"></h:outputText>
                                                    </rich:column> 
                                                    <f:selectItems value="#{pickList.freeItems}" var="item" itemLabel="#{item}" itemValue="#{item}"/>
                                          </rich:pickList>
                                          <a:commandButton action="#{pickList.save}" value="Save" /> 
                                </h:form>
                      </h:body>
            </html>
            
            
            • 3. Re: RF 4.2 - pickList doesn't use value attribute
              iabughosh

              add also item 4 and item 5 to the free items, free items must contain all the items, selected or not.

              • 4. Re: RF 4.2 - pickList doesn't use value attribute
                pczekaj

                Thank you for you help, rich:pickList works as expected for both collection of strings and also my custom objects. Adding all elements to "freeItems" helped, that's the difference between using RF 3.3 rich:listShuttle and RF 4.2 rich:pickList.