I am creating a web application, where you have to read a list of objects / entities from a DB and populate it in a JSF
. I am unable to
I'm doing it like this:
Models are ViewScoped
converter:
@Named
@ViewScoped
public class ViewScopedFacesConverter implements Converter, Serializable
{
private static final long serialVersionUID = 1L;
private Map converterMap;
@PostConstruct
void postConstruct(){
converterMap = new HashMap<>();
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
String selectItemValue = String.valueOf( object.hashCode() );
converterMap.put( selectItemValue, object );
return selectItemValue;
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String selectItemValue){
return converterMap.get(selectItemValue);
}
}
and bind to component with:
If you will use entity id rather than hashCode you can hit a collision- if you have few lists on one page for different entities (classes) with the same id