1 Reply Latest reply on Feb 18, 2009 9:59 AM by nbelaevski

    ListShuttle has invalid value expression

    roele

      I fighting with a strange problem for couple of hours now and cant find the cause.

      I am using a ListShuttle which contains specific ListShuttleItems. Now because this List has a large value of entries i added a simple search input text field to filter the ListShuttle source result list. This works fine as long i do not move items to the target source list and firing the search again.
      The filtering itself is simple and just does not add items to the source list which are not like the search string from the input field.

      According to several forum posts here there are some things to consider when using ListShuttle and Converters. I checked my code and it seems to fulfill these requirements which are: Object is serializable and overrides equals and hashCode.

      The code looks as following:

      ShuttleItem

      public class ListShuttleItem implements Serializable {
      
       private static final long serialVersionUID = -3443423759756411570L;
      
       private String label;
      
       private String name;
      
       private String applicationName = "";
      
       public ListShuttleItem() {}
      
       public ListShuttleItem(String label, String cn, String applicationCn) {
       this.label = label;
       //remove organization hint in case of OrganizationApplicationRole
       if(cn != null &&
       cn.indexOf(":") > -1) {
       cn = cn.substring(0,cn.indexOf(":"));
       }
       this.name = cn;
       this.applicationName = (applicationCn == null) ? "" : applicationCn;
       }
      
       public String getLabel() {
       return label;
       }
      
       public void setLabel(String label) {
       this.label = label;
       }
      
       public String getName() {
       return name;
       }
      
       public void setName(String name) {
       if(name != null &&
       name.indexOf(":") > -1) {
       name = name.substring(0,name.indexOf(":"));
       }
       this.name = name;
       }
      
       public String getApplicationName() {
       return applicationName;
       }
      
       public void setApplicationName(String applicationName) {
       this.applicationName = applicationName;
       }
      
       @Override
       public String toString() {
       return "{" +
       label + ", " +
       name + ", " +
       applicationName +
       "}";
       }
      
       @Override
       public boolean equals(Object o) {
      
       if(this == o) return true;
      
       if(null == o) return false;
      
       if( !(o instanceof ListShuttleItem) ){
       return false;
       }
      
       ListShuttleItem obj = (ListShuttleItem) o;
      
       return (
       label.equals(obj.getLabel()) &&
       name.equals(obj.getName()) &&
       applicationName.equals(obj.getApplicationName())
       );
      
       }
      
       @Override
       public int hashCode() {
       int result = 17;
       result = 31 * result + label.hashCode();
       result = 31 * result + name.hashCode();
       result = 31 * result + applicationName.hashCode();
       return result;
       }
      
      }
      


      Converter
      public class ListShuttleItemConverter implements Converter {
      
       public ListShuttleItemConverter() {}
      
       public Object getAsObject(FacesContext ctx, UIComponent component, String value)
       throws ConverterException {
       if(value != null){
       String[] opts = value.split("#");
       return new ListShuttleItem(opts[0], opts[1], (opts.length == 3) ? opts[2] : "");
       }
       return null;
       }
      
       public String getAsString(FacesContext arg0, UIComponent arg1, Object value)
       throws ConverterException {
      
       if(null == value) return "";
      
       ListShuttleItem i = (ListShuttleItem) value;
       return i.getLabel() + "#" + i.getName() + "#" + i.getApplicationName();
      
       }
      
      
      }
      


      Any hint is highly appreciated

      Setup:
      MyFaces 1.2.4
      Tomahawk 1.1.7
      Facelets 1.1.14
      RichFaces 3.2.1.GA