title: Conversion Error setting value '52' for 'null Converter'
body: <p>I'm new to JSF and I have been trying to store data from a form that uses a h:selectOneMenu to get the category of a product. The h:selectOneMenu is being populated from the DB, however, when trying to store a product in the DB, I am getting an error: Conversion Error setting value '52' for 'null Converter'.  I have reviewed similar problems in StackOverflow and tutorials online but I am still getting the error.</p>
  
  <p>This is the xhtml:</p>
  
  <pre><code>&lt;h:selectOneMenu id="category_fk" value="#{productController.product.category_fk}" 
                                   converter="#{categoryConverter}" title="Category_fk" &gt;
                      &lt;!-- DONE: update below reference to list of available items--&gt;
                      &lt;f:selectItems value="#{productController.categoryList}" var="prodCat"
                                     itemValue="#{prodCat}" itemLabel="#{prodCat.name}"/&gt;
                  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>This is the product controller:</p>
  
  <pre><code>@Named
  @RequestScoped
  public class ProductController {
  
      @EJB
      private ProductEJB productEjb;
      @EJB
      private CategoryEJB categoryEjb;
  
      private Product product = new Product();
      private List&lt;Product&gt; productList = new ArrayList&lt;Product&gt;();
  
      private Category category;
      private List&lt;Category&gt; categoryList = new ArrayList&lt;Category&gt;();
  
      public String doCreateProduct()
      {
          product = productEjb.createProduct(product);
          productList = productEjb.findAllProducts();
          return "listProduct";
      }
  
      @PostConstruct
      public void init()
      {
          categoryList = categoryEjb.findAllCategory();
          productList = productEjb.findAllProducts();
      }        
  
      // Getters/Setters and other methods omitted for simplicity
  </code></pre>
  
  <p>This is the EJB simplified for simplicity:</p>
  
  <pre><code>   @Stateless
      public class ProductEJB{
  
          @PersistenceContext(unitName = "luavipuPU")
          private EntityManager em;
  
          public List&lt;Product&gt; findAllProducts()
          {
              TypedQuery&lt;Product&gt; query = em.createNamedQuery("findAllProducts", Product.class);
              return query.getResultList();
          }
  
          public Product createProduct(Product product)
          {
              em.persist(product);
              return product;
          }    
  
      }
  </code></pre>
  
  <p>This is the product Entity simplified for simplicity:</p>
  
  <pre><code>@Entity
  @NamedQueries({
      @NamedQuery(name="findAllProducts", query = "SELECT p from Product p")
  })
  public class Product implements Serializable
  {
      private static final long serialVersionUID = 1L;
  
      @Id @GeneratedValue(strategy= GenerationType.AUTO)
      private int product_id;
      private String name;
      private String description;
      protected byte[] imageFile;
      private Float price;
      @Temporal(TemporalType.TIMESTAMP)
      private Date dateAdded;
      @ManyToOne    
      private Category category_fk;
      @ManyToOne
      private SaleDetails saleDetails_fk;
  </code></pre>
  
  <p>This is the updated converter I am using:</p>
  
  <pre><code>@ManagedBean
  @FacesConverter(value="categoryConverter")
  public class CategoryConverter implements Converter{
  
      @PersistenceContext
      private transient EntityManager em;
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          return em.find(Category.class, new Integer(value));
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
  
          Category category;
          category = (Category) value;
          return String.valueOf(category.getCategory_id());
  
      }
  
  }
  </code></pre>
  
  <p>The code has been updated from the Orignal problem, the code perfectly works now.</p>