title: JSF java.lang.IllegalArgumentException: Cannot convert 5 of type class java.lang.Integer to class
body: <p>i get new Error with converter </p>
  
  <pre><code>javax.faces.component.UpdateModelException: java.lang.IllegalArgumentException: Cannot convert 5 of type class java.lang.Integer to class com.jpa.entity.Groups
      at javax.faces.component.UIInput.updateModel(UIInput.java:839)
      at javax.faces.component.UIInput.processUpdates(UIInput.java:722)
      at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
      at javax.faces.component.UIForm.processUpdates(UIForm.java:270)
      at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
      at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
      at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1239)
      at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
      at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
      at java.lang.Thread.run(Thread.java:619)
  Caused by: java.lang.IllegalArgumentException: Cannot convert 5 of type class java.lang.Integer to class com.jpa.entity.Groups
      at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:397)
      at com.sun.el.parser.AstValue.setValue(AstValue.java:194)
      at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:286)
      at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:124)
      at javax.faces.component.UIInput.updateModel(UIInput.java:805)
  </code></pre>
  
  <p><strong>5 is value of GroupsID</strong></p>
  
  <p>i was read tutorial at <a href="http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html" rel="nofollow noreferrer">http://balusc.blogspot.com/2007/09/objects-in-hselectonemenu.html</a> 
  and <a href="http://www.javabeat.net/articles/15-introduction-to-jsf-core-tags-library-2.html" rel="nofollow noreferrer">http://www.javabeat.net/articles/15-introduction-to-jsf-core-tags-library-2.html</a>
  but how can i convert it? because equals and hashcode method i was override in class Groups</p>
  
  <p>Groups Class</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package com.jpa.entity;
  
  import java.io.Serializable;
  import java.util.List;
  import javax.persistence.Basic;
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  
  /**
   *
   * @author KencyWindy
   */
  @Entity
  @Table(name = "groups")
  @NamedQueries({
      @NamedQuery(name = "Groups.findAll", query = "SELECT g FROM Groups g"),
      @NamedQuery(name = "Groups.findByGroupid", query = "SELECT g FROM Groups g WHERE g.groupid = :groupid"),
      @NamedQuery(name = "Groups.findByGroupname", query = "SELECT g FROM Groups g WHERE g.groupname = :groupname")})
  public class Groups implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "groupid")
      private Integer groupid;
      @Basic(optional = false)
      @Column(name = "groupname")
      private String groupname;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "groups")
      private List&lt;TblUser&gt; tblUserList;
  
      public Groups() {
      }
  
      public Groups(Integer groupid) {
          this.groupid = groupid;
      }
  
      public Groups(Integer groupid, String groupname) {
          this.groupid = groupid;
          this.groupname = groupname;
      }
  
      public Integer getGroupid() {
          return groupid;
      }
  
      public void setGroupid(Integer groupid) {
          this.groupid = groupid;
      }
  
      public String getGroupname() {
          return groupname;
      }
  
      public void setGroupname(String groupname) {
          this.groupname = groupname;
      }
  
      public List&lt;TblUser&gt; getTblUserList() {
          return tblUserList;
      }
  
      public void setTblUserList(List&lt;TblUser&gt; tblUserList) {
          this.tblUserList = tblUserList;
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (groupid != null ? groupid.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof Groups)) {
              return false;
          }
          Groups other = (Groups) object;
          if ((this.groupid == null &amp;&amp; other.groupid != null) || (this.groupid != null &amp;&amp; !this.groupid.equals(other.groupid))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "com.jpa.entity.Groups[groupid=" + groupid + "]";
      }
  
  }
  </code></pre>
  
  <p>TblUser Class</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package com.jpa.entity;
  
  import java.io.Serializable;
  import java.util.Date;
  import javax.persistence.Basic;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.ManyToOne;
  import javax.persistence.NamedQueries;
  import javax.persistence.NamedQuery;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  
  /**
   *
   * @author KencyWindy
   */
  @Entity
  @Table(name = "tbl_user")
  @NamedQueries({
      @NamedQuery(name = "TblUser.findAll", query = "SELECT t FROM TblUser t"),
      @NamedQuery(name = "TblUser.findByUserid", query = "SELECT t FROM TblUser t WHERE t.userid = :userid"),
      @NamedQuery(name = "TblUser.findByUsername", query = "SELECT t FROM TblUser t WHERE t.username = :username"),
      @NamedQuery(name = "TblUser.findByPassword", query = "SELECT t FROM TblUser t WHERE t.password = :password"),
      @NamedQuery(name = "TblUser.findByDob", query = "SELECT t FROM TblUser t WHERE t.dob = :dob"),
      @NamedQuery(name = "TblUser.findByAddress", query = "SELECT t FROM TblUser t WHERE t.address = :address")})
  public class TblUser implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "userid")
      private Integer userid;
      @Basic(optional = false)
      @Column(name = "username")
      private String username;
      @Basic(optional = false)
      @Column(name = "password")
      private String password;
      @Basic(optional = false)
      @Column(name = "dob")
      @Temporal(TemporalType.TIMESTAMP)
      private Date dob;
      @Basic(optional = false)
      @Column(name = "address")
      private String address;
      @JoinColumn(name = "igroup", referencedColumnName = "groupid")
      @ManyToOne(optional = false)
      private Groups groups;
  
      public TblUser() {
      }
  
      public TblUser(Integer userid) {
          this.userid = userid;
      }
  
      public TblUser(Integer userid, String username, String password, Date dob, String address) {
          this.userid = userid;
          this.username = username;
          this.password = password;
          this.dob = dob;
          this.address = address;
      }
  
      public Integer getUserid() {
          return userid;
      }
  
      public void setUserid(Integer userid) {
          this.userid = userid;
      }
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public Date getDob() {
          return dob;
      }
  
      public void setDob(Date dob) {
          this.dob = dob;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public Groups getGroups() {
          return groups;
      }
  
      public void setGroups(Groups groups) {
          this.groups = groups;
      }
  
      public Integer getGroupID(){
          return this.groups.getGroupid();
      }
  
      public void setGroupID(Integer iGroup){
          this.groups = new Groups(iGroup);
      }
  
      @Override
      public int hashCode() {
          int hash = 0;
          hash += (userid != null ? userid.hashCode() : 0);
          return hash;
      }
  
      @Override
      public boolean equals(Object object) {
          // TODO: Warning - this method won't work in the case the id fields are not set
          if (!(object instanceof TblUser)) {
              return false;
          }
          TblUser other = (TblUser) object;
          if ((this.userid == null &amp;&amp; other.userid != null) || (this.userid != null &amp;&amp; !this.userid.equals(other.userid))) {
              return false;
          }
          return true;
      }
  
      @Override
      public String toString() {
          return "com.jpa.entity.TblUser[userid=" + userid + "]";
      }
  
  }
  </code></pre>
  
  <p>method Grouplist</p>
  
  <pre><code>&gt;  public javax.faces.model.SelectItem[]
  &gt; getGroupList(){
  &gt;         SelectItem[] options = null;
  &gt; 
  &gt;             List&lt;Groups&gt; iGroup = userBean.retrieveAllGroup();
  &gt;             if(iGroup != null &amp;&amp; iGroup.size() &gt; 0){
  &gt;                 options = new SelectItem[iGroup.size()];
  &gt;                 int i = 0 ;
  &gt;                 for(Groups groups : iGroup){
  &gt;                     options[i++] = new SelectItem(groups.getGroupid(),
  &gt; groups.getGroupname());
  &gt;                 }
  &gt;             }
  &gt; 
  &gt;         return options;
  &gt;     }
  </code></pre>
  
  <p>JSF file</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--
  To change this template, choose Tools | Templates
  and open the template in the editor.
  --&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        &gt;
      &lt;h:head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/&gt;
          &lt;title&gt;TODO supply a title&lt;/title&gt;
  
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;f:view&gt;
              &lt;h:form&gt;
                  &lt;h1&gt;&lt;h:outputText value="Create/Edit"/&gt;&lt;/h1&gt;
                  &lt;h:panelGrid columns="2"&gt;
                       &lt;h:outputLabel value="Username" for="username" /&gt;
                      &lt;h:inputText id="username" value="#{userController.user.username}" title="Username" required="true" requiredMessage="The Username field is required."/&gt;
                      &lt;h:outputLabel value="Password:" for="password" /&gt;
                      &lt;h:inputText id="password" value="#{userController.user.password}" title="Password" required="true" requiredMessage="The Password field is required."/&gt;
                      &lt;h:outputLabel value="Dob:" for="dob" /&gt;
                      &lt;h:inputText id="dob" value="#{userController.user.dob}" title="Dob" required="true" requiredMessage="The Dob field is required."&gt;
                          &lt;f:convertDateTime pattern="MM/dd/yyyy" /&gt;
                      &lt;/h:inputText&gt;
                      &lt;h:outputLabel value="Address:" for="address" /&gt;
                      &lt;h:inputText id="address" value="#{userController.user.address}" title="Address" required="true" requiredMessage="The Address field is required."/&gt;
                      &lt;h:inputHidden/&gt;
                      &lt;h:selectOneMenu id="igroup" value="#{userController.user.groups}" title="Igroup" required="true" requiredMessage="The Igroup field is required."&gt;
                          &lt;!-- TODO: update below reference to list of available items--&gt;
                          &lt;f:selectItems value="#{userController.groupList}"/&gt;
                          &lt;f:converter converterId="javax.faces.Integer"/&gt;
                      &lt;/h:selectOneMenu&gt;
                  &lt;/h:panelGrid&gt;
                  &lt;h:commandButton value="Ok" action="#{userController.addUser}"/&gt;
              &lt;/h:form&gt;
          &lt;/f:view&gt;
  
  
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>