I have a big problem with Converter class. I am using h:selectOneMenu to select a “category” for my Enetity “Product”. When i submit form, then i get following error :
•Conversion Error setting value ” for ‘null Converter’.
I can not find what is wrong with my implementation.
Also i am searching how to do that working with Seam-Faces…
Any ideas?
Thanx.
I am using JSF Mojarra 2.1.2 (FCS 20110613), GlassFish v 3.1, PrimeFaces 2.x, PrettyFaces 3.x and JPA 2.0.
MY JSF page:
<h:selectOneMenu id="selectCategory"
value="#{productController.category}">
<f:selectItems value="#{categoryController.listCategory()}" var="category" itemLabel="#{category.name}" itemValue="#{category}"/>
<f:converter converterId="categoryConverter" />
</h:selectOneMenu>
MY Converter class :
@FacesConverter(forClass=Category.class, value="categoryConverter")
public class CategoryConverter implements Converter {
private CategoryController ctrl;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
ctrl = (CategoryController) context.getApplication().getELResolver().getValue(
context.getELContext(), null, "categoryController");
Category category = ctrl.findById(Integer.valueOf(value));
return category;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return "" + ((Category) value).getCategoryid();
}
}
some part of my ProductController Class :
@ManagedBean(name = "productController")
@RequestScoped
ProductController class
public ProductController{
private Category category;
//getters :: setters
Thanks but I had tried it with system.outs. Values are send correctly by submit and returned right category object for the given value (#ID). but still having the same error.
Anyway…. I have found the problem. Converter works fine as expected.
Only thing that causes the error was that the field product.”image” . I had no converter for image field. When i removed this line from JSF form, it is submitted without errors.
Type of image property is a byte and so it also needs to be converted in the JSF such as other fields that are not a String.
just a beginner error i know:)
StringToByteConverter:
here is an example