1 Reply Latest reply on Mar 13, 2009 7:38 PM by Nick Belaevski

    Possible listShuttle bug?

    David Fuchs Newbie

      Hello,

      I came across a problem when using rich:listShuttle. I've solved the problem for my own application, but I believe there may be a component bug involved.

      I'm using rich:listShuttle as part of a wizard that I've implemented with a4j:include. The first view contains the listShuttle, and a 'Next' button. The second view contains a 'Back' button and 'Close' button. At first, clicking 'Next' works fine, but if I then click 'Back' and then 'Next' again, I get the following error on the view with the listShuttle:

      "Component j_id30:j_id142:userListShuttle has invalid value expression null"
      


      Here is the definition of my listShuttle:

      <rich:listShuttle
       id="userListShuttle"
       sourceValue="#{wizardBean.sourceUsers}"
       targetValue="#{wizardBean.targetUsers}"
       converter="userConverter"
       var="user"
       sourceListWidth="280" targetListWidth="280"
       listsHeight="128"
       sourceCaptionLabel="Available Users"
       targetCaptionLabel="Targeted Users"
       orderControlsVisible="false"
       fastOrderControlsVisible="false">
       <rich:column width="16">
       <h:graphicImage value="/images/icon_user.png" width="16" height="16"/>
       </rich:column>
       <rich:column>
       <h:outputText value="#{user.name}"/>
       </rich:column>
      </rich:listShuttle>
      


      Here is the definition of my User object:

      public class User {
       private String name;
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       this.name = name;
       }
      


      And here is the definition of my Converter:

      public class UserConverter implements Converter {
       public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) {
       HtmlListShuttle shuttle = (HtmlListShuttle)uiComponent;
       List<User> users = (List<User>)shuttle.getSourceValue();
      
       for (User user : users) {
       if (user.getName().equals(s)) {
       return user;
       }
       }
      
       return null;
       }
      
       public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) {
       return ( o == null ) ? "" : ((User)o).getName();
       }
      }
      


      The issue was that one of my User objects had a name that contained multiple spaces in it. If, for example, I displayed in the listShuttle the name 'John Smith', it would work fine no matter how many times I went Next and Back. But if the name was 'John__Smith' (the underscores represent multiple spaces, since the browser is trimming them out), then it gave me a validation error. Upon further investigation, the getAsObject() call in my converter was indeed being called with 'John Smith' even when the underlying data was 'John__Smith' (multiple spaces).

      I believe the problem is a result of the web browser combining multiple spaces into one space (same reason I need to use underscores to represent spaces in this post), and the component is trying to match this modified name against the collection, but with dire results.

      I've since fixed my data and removed the additional spaces, so the issue is resolved for me. That said, I don't believe getAsObject() should be called with a different value than the one that was originally provided to the component. What do you guys think?

      Thanks!