title: Pass Object value in Primefaces SelectOneMenu
body: <p>Hello i am Using PrimeFaces 4.0 and i need to pass object value in SelectOneMenu.
  I am using converter to convert that from string format to Class object format.
  These are the code files please help me...</p>
  
  <p><strong>lablevalue.xhtml</strong></p>
  
  <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" 
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://xmlns.jcp.org/jsf/core"&gt;
      &lt;h:head&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;h:form id="myform"&gt; 
              &lt;p:growl showDetail="true"&gt;&lt;/p:growl&gt;
              &lt;p:selectOneMenu value="#{itemlableAcction.idCard}" &gt;
                  &lt;f:converter converterId="converter.SelectMenUConverter" /&gt;
                  &lt;f:selectItem itemLabel="Select" itemValue="" /&gt;
                  &lt;f:selectItems value="#{itemlableAcction.idCards}" var="idv" itemLabel="#{idv.name}" itemValue="#{idv}" /&gt;
              &lt;/p:selectOneMenu&gt;
              &lt;h:commandButton action="#{itemlableAcction.onclickSubmit}" value="Submit"&gt;&lt;/h:commandButton&gt;
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>ItemlableAcction</strong> </p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  import javax.faces.bean.ManagedBean;
  import bo.IdCard;
  
  @ManagedBean
  public class ItemlableAcction {
  
      List&lt;IdCard&gt; idCards = new ArrayList&lt;IdCard&gt;();
  
      IdCard idCard;
  
      public Object getIdCard() {
          return idCard;
      }
  
      public void setIdCard(IdCard idCard) {
          this.idCard = idCard;
      }
  
      public List&lt;IdCard&gt; getIdCards() {
          return idCards;
      }
  
      public void setIdCards(List&lt;IdCard&gt; idCards) {
          this.idCards = idCards;
      }
  
      public ItemlableAcction() {
          IdCard card1 = new IdCard();
          card1.setId(1);
          card1.setName("ABC");
          card1.setAddress("USA");
          idCards.add(card1);
          IdCard card2 = new IdCard();
          card2.setId(2);
          card2.setName("MNO");
          card2.setAddress("INDIA");
          idCards.add(card2);
          IdCard card3 = new IdCard();
          card3.setId(3);
          card3.setName("XYZ");
          card3.setAddress("Chaina");
          idCards.add(card3);
      }
  
      public String onclickSubmit() {
          IdCard ic = (IdCard) idCard;
          System.out.println("In action id values are " + ic.getId() + " " + ic.getAddress());
          return "";
      }
  
  }
  </code></pre>
  
  <p><strong>SelectMenUConverter</strong></p>
  
  <pre><code>import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.convert.Converter;
  import javax.faces.convert.FacesConverter;
  
  import bo.IdCard;
  
  @FacesConverter("converter.SelectMenUConverter")
  public class SelectMenUConverter implements Converter {
  
      public SelectMenUConverter() {
          System.out.println("Inside converter");
      }
  
      public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
          System.out.println("One" + arg2);
          IdCard idCard = new IdCard(arg2);
          return idCard;
      }
  
      public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
          System.out.println("Two" + value);
          return value.toString();
      }
  
  }
  </code></pre>
  
  <p><strong>Idcard</strong></p>
  
  <pre><code>public class IdCard {
  
      String name;
  
      int id;
  
      String address;
  
      public IdCard() {
      }
  
      public IdCard(String name) {
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
  }
  </code></pre>