Converters do the amazing job of take an input value in UIInput component and then return an specific object to be used in you back beans, actually we have many kinds of converters, we are introducing now a new kind of converter that can takes an input value from some UIInput components and the call a generic persistence layer stuff to return the desired entity instance.

Entity Converter using EntityLoader

This approach lets the user create you own entity loader stuff that load the entity using the persistence layer of your preference. The only thing that you need to configure in your application is your custom EntityLoader interface implementation, to do this, you must add the following web.xml context param:


and the configuration below on facelets tag definition:


and your app.util.EntityLoader can be somethinkg like this:

package app.util;
import java.io.Serializable;

import org.hibernate.Session;

public class EntityLoader implements br.eti.faces.entityconverter.EntityLoader {

        public Object getEntity(Class type, Serializable id) {
                Session session = HibernateUtil.sessaoAtual();
                Object object = sessao.get(type, id);
                return object;

and then you can use in your pages in this way:

<h:selectOneMenu value="#{bean.selectedEntity}" 
   <t:selectItems value="#{bean.entities}"
      var="entity" itemLabel="#{entity.name}"
      itemValue="#{entity}" />


<h:selectOneMenu value=“#{bean.selectedEntity}”>
   <fbr:entityConverter entity="package.Entity"
   <t:selectItems value="#{bean.entities}"
      var="entity" itemLabel="#{entity.nome}"
      itemValue="#{entity}" />

reading the submited value in your bean:

Entity entity = selectedEntity; 

right now it's only tested with UISelectOne, but should works with other UIInputs except UISelectMany.

You can download the binaries here:


Entity_Converters (last edited 2009-09-20 23:00:53 by localhost)