-
1. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 29, 2007 5:57 PM (in response to smithbstl)Ok it seems that my equals() method in DepartmentSection is failing which I am sure is the problem
public boolean equals(Object object) { if (object == this) return true; if (!(object instanceof DepartmentSection)) return false; DepartmentSection other = (DepartmentSection)object; if (!(other.getDepartmentSectionId() == this.getDepartmentSectionId())) return false; return true; }
Its failing on the instanceof check. I can't figure that one out. I would assume that it would have something to do with the DepartmentSectionList declaration on the Department class but it all seems correct.
Here is the declaration//Department Entity @OneToMany(cascade = CascadeType.ALL, mappedBy = "department") private List<DepartmentSection> departmentSectionList = new ArrayList<DepartmentSection>(); public List<DepartmentSection> getDepartmentSectionList() { return this.departmentSectionList; } public void setDepartmentSectionList(List<DepartmentSection> departmentSectionList) { this.departmentSectionList = departmentSectionList; }
-
2. Re: s:selectItems problems Seam 2 Beta1
pmuir Aug 30, 2007 5:00 AM (in response to smithbstl)What is departmentSectionId? Do you not need to use .equals on that as well?
-
3. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 30, 2007 8:25 AM (in response to smithbstl)Its a Long so I guess .equals would work but the method is failing on this condition
if (!(object instanceof DepartmentSection)) return false; -
4. Re: s:selectItems problems Seam 2 Beta1
pmuir Aug 30, 2007 8:32 AM (in response to smithbstl)What class is object? What's its hierachy?
-
5. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 30, 2007 9:30 AM (in response to smithbstl)It has no hierarchy, just an entity class that implements Serializable
-
6. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 30, 2007 9:39 AM (in response to smithbstl)Ok in debugging further, it looks like object is null when the equals method is called.
-
7. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 30, 2007 10:23 AM (in response to smithbstl)Ok, it has something to do with department.departmentSectionList
I replaced the middle select box to use a crud entity query instead (I removed the first box so the second is not filtered at all)
Strangely it works with the entity query
This DOES NOT WORK<h:selectOneMenu id="departmentSection_select" value="#{departmentSection}"> <s:selectItems label="#{deptSection.departmentSectionName}" value="#{department.departmentSectionList}" var="deptSection" noSelectionLabel="(none)"/> <s:convertEntity/> <a4j:support event="onchange" ajaxSingle="true" reRender="complaintType_select"/> </h:selectOneMenu>
Here is the new selectOneMenu that works (see the value of s:selectItems for the difference)<h:selectOneMenu id="departmentSection_select" value="#{departmentSection}"> <s:selectItems label="#{deptSection.departmentSectionName}" value="#{allDepartmentSections.resultList}" var="deptSection" noSelectionLabel="(none)"/> <s:convertEntity/> <a4j:support event="onchange" ajaxSingle="true" reRender="complaintType_select"/> </h:selectOneMenu>
Why does it not work when lazy loading the departmentSectionList from Department? -
8. Re: s:selectItems problems Seam 2 Beta1
smithbstl Aug 30, 2007 12:41 PM (in response to smithbstl)Ok, I got it working. I was not outjecting the department or departmentSection entities which was a problem.
I also had to rewrite the equals() method of DepartmentSectionpublic boolean equals(Object other) { if (other == null) { return false; } if (other instanceof DepartmentSection) { DepartmentSection that = (DepartmentSection) other; if (that.getDepartmentSectionId() != null && this.getDepartmentSectionId() != null) { return this.departmentSectionId.equals(that.departmentSectionId); } else { return (this == that); } } else { return false; } }
Since jsf does not guarantee how many times equals() will be called, it was being called 3 times during process validations but it was passing null objects in for "other" and at other times seam was passing proxy objects that were not null but the fields were not initialized.
Is there a more concise way to cover all the bases with equals()? Or should implement a similar method on all my entities?