8 Replies Latest reply on Aug 30, 2007 12:41 PM by Brian Smith

    s:selectItems problems Seam 2 Beta1

    Brian Smith Apprentice

      I am having a strange problem with a selectOneMenu and s:selectItems

      I have a series of menus that filter based on the previous selection.

       <h:selectOneMenu id="department_select" value="#{department}">
       <s:selectItems label="#{dept.departmentNumber} - #{dept.departmentName}"
       value="#{allDepartments.resultList}"
       var="dept"/>
       <s:convertEntity/>
       <a4j:support event="onchange"
       actionListener="#{serviceRequestManager.fillDepartmentSectionList}"
       ajaxSingle="true" reRender="departmentSection_select"/>
       </h:selectOneMenu>
      
       <h:selectOneMenu id="departmentSection_select" value="#{departmentSection}">
       <s:selectItems label="#{deptSection.departmentSectionName}"
       value="#{departmentSectionList}"
       var="deptSection"
       noSelectionLabel="(none)"/>
       <s:convertEntity/>
       <a4j:support event="onchange"
       actionListener="#{serviceRequestManager.fillComplaintTypeList}"
       ajaxSingle="true" reRender="complaintType_select"/>
       </h:selectOneMenu>
      
       <h:selectOneMenu id="complaintType_select" value="#{sectionComplaintType}">
       <s:selectItems label="#{sectionComplaint.complaintType.complaintTypeDescription}"
       value="#{sectionComplaintTypeList}"
       var="sectionComplaint"
       noSelectionLabel="(none)"/>
       <s:convertEntity/>
       </h:selectOneMenu>


      The first menu filters the second, the second filters the third. This was working using under Seam 1.2

      When I select from the first box, the second is filtered no problem. When I select the second, I get an error message

      "value is not valid"

      during either the Apply Request Values or Process Validations phase. No stack trace.

      My actionListener is never called. When i choose the "(none)" noSelectionLabel, the actionListener is called.

      Any idea what is going on?


        • 1. Re: s:selectItems problems Seam 2 Beta1
          Brian Smith Apprentice

          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
            Pete Muir Master

            What is departmentSectionId? Do you not need to use .equals on that as well?

            • 3. Re: s:selectItems problems Seam 2 Beta1
              Brian Smith Apprentice

              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
                Pete Muir Master

                What class is object? What's its hierachy?

                • 5. Re: s:selectItems problems Seam 2 Beta1
                  Brian Smith Apprentice

                  It has no hierarchy, just an entity class that implements Serializable

                  • 6. Re: s:selectItems problems Seam 2 Beta1
                    Brian Smith Apprentice

                    Ok in debugging further, it looks like object is null when the equals method is called.

                    • 7. Re: s:selectItems problems Seam 2 Beta1
                      Brian Smith Apprentice

                      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
                        Brian Smith Apprentice

                        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 DepartmentSection

                        public 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?