That's because HTML and HTTP does not understand Java objects. All Java objects are converted to String
when HTML is to be produced by JSF. All HTTP request parameters which are String
are supposed to be converted back to Java object when the submitted form data is to be processed by JSF.
As to your concrete problem, if you have added a <h:message>
, <h:messages>
or the PrimeFaces equivalent to the form (and also updated it on ajax submits), then you should have noticed a conversion error for "null converter". Also, if you have paid attention to the server log, you should also have seen a warning about an unhandled message.
You need to create a custom Converter which converts between MyObj
and its unique String
representation. For example:
@FacesConverter(forClass=MyObj.class)
public class MyObjConverter implements Converter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object valueToRender) {
// Convert MyObj to its unique String representation.
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
// Convert String to MyObj.
}
}
Usually those objects are already stored in some database or mapping by their ID. You then use exactly that ID as unique String
representation.