2 Replies Latest reply on Sep 4, 2008 1:20 PM by Matthias Dickgiesser

    rich:listshuttle converter problem

    Matthias Dickgiesser Newbie

      Greetings,

      I'm having trouble getting my List Shuttle to work. I'm using it to assign certain User Groups. On first invocation i always receive a faces-error message like this:

      "Component j_id_jsp_488724587_1:shuttle has invalid value expression com.tqg.lcm.manager.modules.useradmin.UserGroupVO@134831a6"

      When i switch back to my shuttle site and try the same action again everything works fine, it just occurs on the first invocation. I guess the problem is related to the overwriting of the hasCode() and equals() methods. I'm not very experienced with that and I used and adjusted the methods from the ListShuttle demo. Perhaps you can help me out ? Here is my Code:

      My Bean (including the hashCode() and equals() methods):

      package com.tqg.lcm.manager.modules.useradmin;
      
      import java.io.Serializable;
      
      
      public class UserGroupVO implements Serializable {
       protected long id;
       protected String groupname;
       protected String comment;
       protected String lastuser;
       protected String lastupdate;
      
       /* GETTERS AND SETTERS */
      
      
       public int hashCode() {
       final int prime = 31;
       int result = 1;
       result = prime * result + ((groupname == null) ? 0 : groupname.hashCode());
       result = prime * result + ((comment == null) ? 0 : comment.hashCode());
       result = prime * result + ((lastuser == null) ? 0 : lastuser.hashCode());
       result = prime * result + ((lastupdate == null) ? 0 : lastupdate.hashCode());
       result = prime * result + (int)id;
       return result;
       }
      
       public boolean equals(Object obj) {
       if (this == obj)
       return true;
       if (obj == null)
       return false;
       if (getClass() != obj.getClass())
       return false;
       UserGroupVO other = (UserGroupVO) obj;
      
       if (groupname == null) {
       if (other.groupname != null)
       return false;
       } else if (!groupname.equals(other.groupname))
       return false;
       if (comment == null) {
       if (other.comment != null)
       return false;
       } else if (!comment.equals(other.comment))
       return false;
       if (lastuser == null) {
       if (other.lastuser != null)
       return false;
       } else if (!lastuser.equals(other.lastuser))
       return false;
       if (lastupdate == null) {
       if (other.lastupdate != null)
       return false;
       } else if (!lastupdate.equals(other.lastupdate))
       return false;
       if (id != other.id)
       return false;
       return true;
       }
      
      
      
      }
      


      The list shuttle jsp:

      <rich:listShuttle var="item" id="shuttle"
       sourceListWidth="350" targetListWidth="350" listsHeight="310"
       converter="UserGroupConverter" orderControlsVisible="false"
       fastOrderControlsVisible="false"
       removeAllControlLabel="#{msg['shuttle.removeall']}"
       removeControlLabel="#{msg['shuttle.remove']}"
       copyAllControlLabel="#{msg['shuttle.copyall']}"
       copyControlLabel="#{msg['shuttle.copy']}"
       sourceCaptionLabel="#{msg['useradmin.usergroup.availableusergroups']}"
       targetCaptionLabel="#{msg['useradmin.usergroup.targetusergroups']}"
       sourceValue="#{userToUsergroupShuttle.sourceList}"
       targetValue="#{userToUsergroupShuttle.targetList}">
       <h:column>
       <f:facet name="header">
       <h:outputText value="#{msg['useradmin.usergroup']}" />
       </f:facet>
       <h:outputText value="#{item.groupname}" />
       </h:column>
       </rich:listShuttle>
      



      And my converter:
      package com.tqg.lcm.manager.modules.useradmin.converter;
      
      import javax.faces.component.UIComponent;
      import javax.faces.context.FacesContext;
      import javax.faces.convert.Converter;
      import javax.faces.convert.ConverterException;
      
      import com.tqg.lcm.manager.modules.useradmin.UserAdminService;
      import com.tqg.lcm.manager.modules.useradmin.UserGroupVO;
      
      public class UserGroupConverter implements Converter {
      
       UserAdminService uas = new UserAdminService();
      
       public Object getAsObject(FacesContext ctx, UIComponent c, String value) {
      
       if (value == null) {
       return null;
       }
      
       UserGroupVO usergroup = uas.getUserGroupById(Long.parseLong(value));
      
       return usergroup;
       }
      
       public String getAsString(FacesContext ctx, UIComponent c, Object value) {
      
       if (value == null) {
       return null;
       }
      
       UserGroupVO usergroup = null;
      
       try {
       usergroup = (UserGroupVO) value;
       } catch (ClassCastException e) {
       throw new ConverterException("Could not cast to UserGroupVO");
       }
      
       String id = String.valueOf(usergroup.getId());
       return id;
       }
      
      }


      I would be grateful for any help you can provide.

      Exxoo

        • 1. Re: rich:listshuttle converter problem
          Matthias Dickgiesser Newbie

          forgot to mention that on my my first invocation of the lists I'm setting a request parameter to fill the lists initially, on every other invocation i just return the lists managed by the list shuttle. The code of my managed bean:

          public List<UserGroupVO> getSourceList() {
           String flag = FacesContext.getCurrentInstance().getExternalContext()
           .getRequestParameterMap().get("flag");
           if (flag != null) {
           return getInitialSourceList();
           } else {
           return sourceList;
           }
           }
          
           public List<UserGroupVO> getTargetList() {
           String flag = FacesContext.getCurrentInstance().getExternalContext()
           .getRequestParameterMap().get("flag");
           if (flag != null) {
           return getInitialTargetList();
           } else {
           return targetList;
           }
           }
          


          • 2. Re: rich:listshuttle converter problem
            Matthias Dickgiesser Newbie

            sorry just noticed wrong forum, can someone please move this thread to rich faces user forum ? Thanks.