-
1. Re: h:selectOneMenu not showing selected value, always shows first option
nickarls Apr 15, 2009 7:37 AM (in response to vinitadhopia)The entity doesn't have equals() and hashcode() implemented?
-
2. Re: h:selectOneMenu not showing selected value, always shows first option
vinitadhopia Apr 15, 2009 4:15 PM (in response to vinitadhopia)I double checked and all the entities involved definitely have their equals() and hashcode() methods implemented.
FYI, I've added another column containing a <rich:calendar> date component and the data shows up in that component correctly, so I'm still not sure what the problem is.
-
3. Re: h:selectOneMenu not showing selected value, always shows first option
vinitadhopia Apr 15, 2009 5:56 PM (in response to vinitadhopia)I figured it out. Thank you for the help Nikolas. After your post, I took a closer look at my equals() methods. I used Eclipse to generate the equals methods. There were a couple problems with this.
First, the equals methods were generated with comparison's to class names.
public boolean equals(Object obj) { ... if (getClass() != obj.getClass()) return false; ...
This was returning false because the obj.getClass() was returning the class name with $javassist$... appended to it. I assume this is a reference to my entity's proxy object. I had to change this to use an instanceof check instead.
public boolean equals(Object obj) { ... if (!(obj instanceof Course)) return false; ...
I know this is discouraged because a subtype could pass this test, but I'm not sure how else to get around it.
Secondly, the field comparisons were being done with direct access to the object's fields, rather than using the object's getters.
public boolean equals(Object obj) { ... final Course other = (Course) obj; if (description == null) { if (other.description != null) return false; } else if (!description.equals(other.description)) return false; ...
Since this entity is being lazy loaded, accessing the fields directly were returning default values; null, 0, etc... I had to change the comparisons to use the other object's getters.
public boolean equals(Object obj) { ... final Course other = (Course) obj; if (description == null) { if (other.getDescription() != null) return false; } else if (!description.equals(other.getDescription())) return false; ...
Thanks again for pointing me to the equals() methods.
-
4. Re: h:selectOneMenu not showing selected value, always shows first option
nissrine.nakiri Jan 27, 2016 1:37 PM (in response to nickarls)Wow! Your answer was posted in 2009, and now it saved my life ! Thanks Nicklas Karlsson