You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rogerio Pereira <ro...@gmail.com> on 2006/07/22 15:47:39 UTC
EntityConverter
Hi guys!
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 <http://december.com/html/4/element/s.html>: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
Re: EntityConverter
Posted by Rogerio Pereira <ro...@gmail.com>.
Wiki entry created.
2006/7/23, Rogerio Pereira <ro...@gmail.com>:
>
> Matthias and Cagatay (Validator man):
>
> Sure! I'll add to myfaces wiki.
>
> 2006/7/23, Cagatay Civici <ca...@gmail.com>:
>
> > Hi,
> >
> > I'm an hibernate user and cannot think of using hibernate-jsf without an
> > entity converter. We've also written one for our project.
> >
> > http://www.jroller.com/page/cenkcivici?entry=binding_made_easy_with_jsf
> >
> > Also I've written a lookup data resolver to load all the data of the
> > given class to a component as select items.
> >
> > As Matze said, a wiki would be great, I'll also add more Rogerio,
> >
> > Regards,
> >
> > Cagatay
> >
> >
> > On 7/23/06, Matthias Wessendorf <ma...@apache.org> wrote:
> > >
> > > Since I am not a hibernate user but thinking that can be sorta usful
> > > for other people,
> > > may I ask you to add this stuff to our wiki ?
> > >
> > > Thanks,
> > >
> > > On 7/22/06, Rogerio Pereira < rogerio.araujo@gmail.com> wrote:
> > > > Hi guys!
> > > >
> > > > 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>
> > > > 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
> > >
> > >
> > > --
> > > Matthias Wessendorf
> > >
> > > further stuff:
> > > blog: http://jroller.com/page/mwessendorf
> > > mail: mwessendorf-at-gmail-dot-com
> > >
> >
> >
>
>
> --
> Yours truly (Atenciosamente),
>
> Rogério
>
--
Yours truly (Atenciosamente),
Rogério
Re: EntityConverter
Posted by Rogerio Pereira <ro...@gmail.com>.
Matthias and Cagatay (Validator man):
Sure! I'll add to myfaces wiki.
2006/7/23, Cagatay Civici <ca...@gmail.com>:
>
> Hi,
>
> I'm an hibernate user and cannot think of using hibernate-jsf without an
> entity converter. We've also written one for our project.
>
> http://www.jroller.com/page/cenkcivici?entry=binding_made_easy_with_jsf
>
> Also I've written a lookup data resolver to load all the data of the given
> class to a component as select items.
>
> As Matze said, a wiki would be great, I'll also add more Rogerio,
>
> Regards,
>
> Cagatay
>
>
> On 7/23/06, Matthias Wessendorf <ma...@apache.org> wrote:
> >
> > Since I am not a hibernate user but thinking that can be sorta usful
> > for other people,
> > may I ask you to add this stuff to our wiki ?
> >
> > Thanks,
> >
> > On 7/22/06, Rogerio Pereira < rogerio.araujo@gmail.com> wrote:
> > > Hi guys!
> > >
> > > 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>
> > > 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
> >
> >
> > --
> > Matthias Wessendorf
> >
> > further stuff:
> > blog: http://jroller.com/page/mwessendorf
> > mail: mwessendorf-at-gmail-dot-com
> >
>
>
--
Yours truly (Atenciosamente),
Rogério
Re: EntityConverter
Posted by Cagatay Civici <ca...@gmail.com>.
Hi,
I'm an hibernate user and cannot think of using hibernate-jsf without an
entity converter. We've also written one for our project.
http://www.jroller.com/page/cenkcivici?entry=binding_made_easy_with_jsf
Also I've written a lookup data resolver to load all the data of the given
class to a component as select items.
As Matze said, a wiki would be great, I'll also add more Rogerio,
Regards,
Cagatay
On 7/23/06, Matthias Wessendorf <ma...@apache.org> wrote:
>
> Since I am not a hibernate user but thinking that can be sorta usful
> for other people,
> may I ask you to add this stuff to our wiki ?
>
> Thanks,
>
> On 7/22/06, Rogerio Pereira <ro...@gmail.com> wrote:
> > Hi guys!
> >
> > 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>
> > 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
>
>
> --
> Matthias Wessendorf
>
> further stuff:
> blog: http://jroller.com/page/mwessendorf
> mail: mwessendorf-at-gmail-dot-com
>
Re: EntityConverter
Posted by Matthias Wessendorf <ma...@apache.org>.
Since I am not a hibernate user but thinking that can be sorta usful
for other people,
may I ask you to add this stuff to our wiki ?
Thanks,
On 7/22/06, Rogerio Pereira <ro...@gmail.com> wrote:
> Hi guys!
>
> 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>
> 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
--
Matthias Wessendorf
further stuff:
blog: http://jroller.com/page/mwessendorf
mail: mwessendorf-at-gmail-dot-com