5 Replies Latest reply on Oct 4, 2007 4:33 AM by David Joseph

    [2.0.0.CR1] selectManyListbox + convertEntity yields convers

    J Peschier Newbie

      When selecting two items from selectManyListbox I get the following validation error:

      Conversion Error setting value '7 9' for '#{workgroupSelectedStudents}'.


      Evidently person with Id 7 and 9 were selected, but what is causing this validation error? I tried overriding equals() and to match objects on their @Id field. This yielded the same result. Can anyone shed some light on this? I am deploying this on Jboss 4.2.0.GA and Seam 2.0.0.GA.

      addStudent.xhtml
      <s:validateAll>
       <h:outputLabel for="studentlist" value="Pick students" />
       <h:selectManyListbox id="studentlist" size="14" required="true" value="#{workgroupSelectedStudents}">
       <s:selectItems value="#{workgroupAvailableStudents}" var="student" label="#{student.firstName} #{student.prefix} #{student.lastName}"/>
       <s:convertEntity/>
       </h:selectManyListbox>
      </s:validateAll>
      


      WorkgroupStudentDetail.java
      @Stateful
      @Name("workgroupStudentManager")
      @Scope(ScopeType.CONVERSATION)
      @Conversational
      public class WorkgroupStudentDetail implements WorkgroupStudentDetailInterface {
       @In
       private EntityManager entityManager;
      
       @In(required = false)
       @Out(required = false)
       private Collection<Person> workgroupAvailableStudents;
      
       @Out(required = false, scope = ScopeType.CONVERSATION)
       private Collection<Person> workgroupSelectedStudents;
      
       @Begin (join = true, flushMode = FlushModeType.MANUAL)
       @Factory("workgroupAvailableStudents")
       public void findStudents() {
       try {
       workgroupAvailableStudents = (Collection<Person>) entityManager.createQuery("SELECT DISTINCT Object(per) FROM Person per").getResultList();
       } catch (Exception e) {
       log.error("Exception occurred in findStudents() [WorkgroupStudentDetail].", e);
       }
       }
      
       // ..
      }
      



      Person.java
      @Entity
      @Table(name = "person")
      public class Person implements Serializable {
      
       private static final long serialVersionUID = 7690407363935244693L;
       private Long personId;
       private School school;
       private String firstName;
       private String prefix;
       private String lastName;
       private Gender gender;
       private Date dateOfBirth;
       private String placeOfBirth;
       private String mobile;
       private String email;
       private String nationality;
       private String edexKey;
       private String pgnoNumber;
       private Date startDate;
       private Date endDate;
       private Boolean active;
       private Boolean critical;
      
       @Override
       public String toString() {
       return getPersonId() == null ? null : getPersonId().toString();
       }
      
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       @Column(name = "person_id")
       public Long getPersonId() {
       return personId;
       }
      
       protected void setPersonId(Long personId) {
       this.personId = personId;
       }
      // ..
      


        • 1. Re: [2.0.0.CR1] selectManyListbox + convertEntity yields con
          J Peschier Newbie

          Oops, meant to say "Deploying this with 2.0.0.CR1", not "2.0.0.GA"

          • 2. Re: [2.0.0.CR1] selectManyListbox + convertEntity yields con
            Pete Muir Master

            Use

            addStudent.xhtml

            <s:validateAll>
             <h:outputLabel for="studentlist" value="Pick students" />
             <h:selectManyListbox id="studentlist" size="14" required="true" value="#{workgroupStudentManager.workgroupSelectedStudents}">
             <s:selectItems value="#{workgroupAvailableStudents}" var="student" label="#{student.firstName} #{student.prefix} #{student.lastName}"/>
             <s:convertEntity/>
             </h:selectManyListbox>
            </s:validateAll>
            


            WorkgroupStudentDetail.java
            @Stateful
            @Name("workgroupStudentManager")
            @Scope(ScopeType.CONVERSATION)
            @Conversational
            public class WorkgroupStudentDetail implements WorkgroupStudentDetailInterface {
             @In
             private EntityManager entityManager;
            
             @In(required = false)
             @Out(required = false)
             private Collection<Person> workgroupAvailableStudents;
            
             private Collection<Person> workgroupSelectedStudents;
             // Getters and setters for workGroupSelectedStudents
            
             @Begin (join = true, flushMode = FlushModeType.MANUAL)
             @Factory("workgroupAvailableStudents")
             public void findStudents() {
             try {
             workgroupAvailableStudents = (Collection<Person>) entityManager.createQuery("SELECT DISTINCT Object(per) FROM Person per").getResultList();
             } catch (Exception e) {
             log.error("Exception occurred in findStudents() [WorkgroupStudentDetail].", e);
             }
             }
            
             // ..
            }
            


            • 3. Re: [2.0.0.CR1] selectManyListbox + convertEntity yields con
              David Joseph Newbie

              I have the same problem: I noticed then when I try to use a Collection for the selectmanyselectbox value, it won't call the setter method. If I use a List this seems to work fine. Is this wanted behaviour? After all a List is a Collection.

              my code:

              private Collection<SelectionItem> value;
              
               @ManyToMany(cascade = CascadeType.ALL)
               public Collection<SelectionItem> getValue() {
               if (value == null)
               value = new ArrayList<SelectionItem>();
               return value;
               }
              
               public void setValue(Collection<SelectionItem> value) {
               System.out.println("test");
               this.value = value;
               }
              



              <h:selectManyListbox id="genderTrainee" value="#{coach.request.genderTrainee.value}" required="false">
               <s:selectItems value="#{selectionItemManager.findSelectionItemByType('GENDER')}"
               var="g" label="#{g.name}" noSelectionLabel="#{messages.no_selection_label}" />
               <s:convertEntity/>
              </h:selectManyListbox>


              if have the same kind of error:
              Conversion Error setting value '42 43' for '#{coach.request.genderTrainee.value}'.