I created a EntityConverter that get the value entered by user in a UIInput component and when the form is submited this value is converted to an persistence layer entity that you can managed in you bean as u wish, can work with persistence layers that provide a generic way to load entities, e. g. Hibernate session.get(Class, Serializable).
The only thing that u need to do is create a class that implement EntityLoader (that belongs to EntityConverter package). And inside this class u do this:
public Object getEntity(Class type, Serializable id) {
Session session = HibernateUtil.currentSession();
Object object = session.get(type, id);
return object;
}
and then add this entry to your web.xml :
<context-param>
<param-name>br.eti.faces.entityLoader</param-name>
<param-value>br.gov.go.tj.scu.util.EntityLoader</param-value>
</context-param>
using in your page:
<h:selectOneMenu value="#{bean.selectedEntity}"
converter="#{entityConverter.entity['package.Entity;id']}">
<s:selectItems value="#{bean.entities}"
var="entity" itemLabel="#{ entities.name}"
itemValue="#{entity}" />
</h:selectOneMenu>
converter="#{entityConverter.entity['package.Entity;id']}">
<s:selectItems value="#{bean.entities}"
var="entity" itemLabel="#{ entities.name}"
itemValue="#{entity}" />
</h:selectOneMenu>
note: package.Entity is the full class name of your entity and id is the name of your id property in your entity with their get/set methods
reading the submited value in your bean:
Entity entity = selectedEntity;
Uses a little of reflection but tries to do some caching on reflection stuff to enhance performance.
--
Yours truly (Atenciosamente),
Rogério

