3 Replies Latest reply on Jan 28, 2009 8:02 AM by Miloslav Vlach

    ManytoMany and h:selectOneMenu problem

    Jack T. Newbie

      Hello I want to do a manytomany relation two entity and i want using h:selectOneMenu but its giving this error :



      avax.faces.component.UIInput updateModel
      SEVERE: /employee.xhtml @26,76 value="#{employeeHome.instance.projects}": java.lang.IllegalArgumentException: argument type mismatch
      java.lang.IllegalArgumentException: argument type mismatch 





      package org.domain.ManytoMany.entity;
      
      import java.io.Serializable;
      import java.util.Set;
      
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.GeneratedValue;
      import javax.persistence.ManyToMany;
      import javax.persistence.Version;
      import org.hibernate.validator.Length;
      
      @Entity
      public class Employee implements Serializable
      {
          // seam-gen attributes (you should probably edit these)
          private Long id;
          private Integer version;
          private String name;
          protected Set <Project> projects;
          // add additional entity attributes
      
          // seam-gen attribute getters/setters with annotations (you probably should edit)
      
          @Id @GeneratedValue
          public Long getId() {
              return id;
          }
      
          public void setId(Long id) {
              this.id = id;
          }
      
          @Version
          public Integer getVersion() {
              return version;
          }
      
          private void setVersion(Integer version) {
              this.version = version;
          }
      
          @Length(max = 20)
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          @ManyToMany(mappedBy="employees")
           public Set<Project> getProjects() {
                return projects;
           }
      
           public void setProjects(Set<Project> projects) {
                this.projects = projects;
           }
      
      }
      




      package org.domain.ManytoMany.entity;
      
      import java.io.Serializable;
      import java.util.Set;
      
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.GeneratedValue;
      import javax.persistence.ManyToMany;
      import javax.persistence.Version;
      import org.hibernate.validator.Length;
      
      @Entity
      public class Project implements Serializable
      {
          // seam-gen attributes (you should probably edit these)
          private Long id;
          private Integer version;
          private String name;
          protected Set <Employee> employees;
          // add additional entity attributes
      
          // seam-gen attribute getters/setters with annotations (you probably should edit)
      
          @Id @GeneratedValue
          public Long getId() {
              return id;
          }
      
          public void setId(Long id) {
              this.id = id;
          }
      
          @Version
          public Integer getVersion() {
              return version;
          }
      
          private void setVersion(Integer version) {
              this.version = version;
          }
      
          @Length(max = 20)
          public String getName() {
              return name;
          }
      
          public void setName(String name) {
              this.name = name;
          }
      
          @ManyToMany
           public Set<Employee> getEmployees() {
                return employees;
           }
      
           public void setEmployees(Set<Employee> employees) {
                this.employees = employees;
           }
      
      }
      




      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          template="layout/template.xhtml">
      
      <ui:define name="body">
      
          <h:form id="employeeForm">
      
              <rich:panel>
                  <f:facet name="header">employee</f:facet>
      
                  <s:decorate id="nameField" template="layout/edit.xhtml">
                      <ui:define name="label">Name</ui:define>
                      <h:inputText id="name" required="true"
                                   value="#{employeeHome.instance.name}"/>
                  </s:decorate>
                  
                  <s:decorate id="projectField" template="layout/edit.xhtml">
                      <ui:define name="label">Project</ui:define>
                      <h:selectOneMenu value="#{employeeHome.instance.projects}">
                         <s:selectItems var="project" value="#{projectList.resultList}" label="#{project.name}"></s:selectItems>
                        <s:convertEntity></s:convertEntity>
                      </h:selectOneMenu>
                  </s:decorate>
      
                  <div style="clear:both"/>
      
              </rich:panel>
      
              <div class="actionButtons">
                  <h:commandButton id="save"
                                value="Save"
                               action="#{employeeHome.persist}"
                             rendered="#{!employeeHome.managed}"/>
                  <h:commandButton id="update"
                                value="Save"
                               action="#{employeeHome.update}"
                             rendered="#{employeeHome.managed}"/>
                  <h:commandButton id="delete"
                                value="Delete"
                               action="#{employeeHome.remove}"
                            immediate="true"
                             rendered="#{employeeHome.managed}"/>
                  <s:button propagation="end"
                                     id="cancel"
                                  value="Cancel"
                                   view="/employeeList.xhtml"/>
              </div>
      
          </h:form>
      
      </ui:define>
      
      </ui:composition>
      



      what is wrong ?