4 Replies Latest reply on Jun 26, 2009 5:25 AM by nimo22

    rich:listShuttle with false hashCode?

    nimo22

      I have a few rich:listShuttles, holding objects and all works well.

      Except this one, and I do not know why.

      Component myForm:myListShuttle has invalid value expression com.MyObject@d759f2e5


      I guess my equals/hashCode for this Object is wrong. This Object has only one property within my equals/hashCode and in my database there exists a Object-Instance with a primary key idObject =0.

      @Override
       public boolean equals(Object o) {
       if (this == o) return true;
       if (o == null || getClass() != o.getClass()) return false;
      
       MyObject that = (MyObject ) o;
       if (idObject != null ? !idObject .equals(that.idObject ) : that.idObject != null) return false;
      
       return true;
       }
      
       @Override
       public int hashCode() {
       int result = idObject != null ? idObject .hashCode() : 0;
      
       return result;
       }




      06:38:12,954 INFO [STDOUT] AfterPhase: INVOKE_APPLICATION 5
      06:38:12,970 INFO [STDOUT] BeforePhase: RENDER_RESPONSE 6
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 1 :1
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 1 :1
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 1 :1
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 101 :101
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 101 :101
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 101 :101
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 102 :102
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 102 :102
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 102 :102
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 103 :103
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 103 :103
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 103 :103
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 104 :104
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 104 :104
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 104 :104
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 105 :105
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 105 :105
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 105 :105
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 50 :50
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 50 :50
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 50 :50
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 51 :51
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 51 :51
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 51 :51
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 2 :2
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 2 :2
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 2 :2
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 3 :3
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 3 :3
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 3 :3
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 4 :4
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 4 :4
      06:38:13,063 INFO [STDOUT] hashCode of Object with ID 4 :4
      06:38:13,965 INFO [STDOUT] AfterPhase: RENDER_RESPONSE 6
      06:38:22,268 INFO [STDOUT] BeforePhase: RESTORE_VIEW 1
      06:38:22,284 INFO [STDOUT] AfterPhase: RESTORE_VIEW 1
      06:38:22,284 INFO [STDOUT] BeforePhase: APPLY_REQUEST_VALUES 2
      06:38:22,393 INFO [STDOUT] AfterPhase: APPLY_REQUEST_VALUES 2


      I also do not know why the printstack prints each object three times.



        • 1. Re: rich:listShuttle with false hashCode?

          You need to declare a converter to the rich shuttle like this

          converter="myConverter"
          


          which a attribute to rich:listshuttle

          and teh converter should take the pain of converting the object to String and string to objetc
          For example here is my code snippet for the same

          public class ApproveCoursesConverter implements Converter {
           @Override
           public Object getAsObject(FacesContext context, UIComponent component,
           String value) {
           String[] tokens = value.split(":");
           return new ApproveVO(tokens[0], Long.parseLong(tokens[1]), tokens[2]);
           }
          
           @Override
           public String getAsString(FacesContext context, UIComponent component,
           Object value) {
           ApproveVO approveVO = (ApproveVO) value;
           return approveVO.getIconURI() + ":" + approveVO.getUserId() + ":"
           + approveVO.getUserName();
           }
          
          }
          
          


          please do similarly to solve your problem


          • 2. Re: rich:listShuttle with false hashCode?
            nimo22

            The converter is not my problem. I use Seams Entity-Converter, which works well for my other listShuttles, but only this one does not work.

            I guess because of my equals/hashCode-Method.

            • 3. Re: rich:listShuttle with false hashCode?
              nimo22

              I do not know, why my hashCodes should be wrong.

              All ID's have different hashCodes. The only thing, what is strange, the printstack prints each object three times.

              • 4. Re: rich:listShuttle with false hashCode?
                nimo22

                I have changed the ID from '0' to '1' for this object which is marked as having 'invalid value expression', but the problem still remains.