-
-
2. Re: How to use converters
lincolnthree Jul 5, 2012 10:16 PM (in response to g00gle88)Here you go, this should help.
http://www.javabeat.net/2007/11/using-converters-in-jsf/
http://www.mkyong.com/jsf2/custom-converter-in-jsf-2-0/
Cheers,
Lincoln
-
3. Re: How to use converters
g00gle88 Jul 6, 2012 8:07 PM (in response to lincolnthree)Hi Lincoln,
Thanks for the reply. I have already read those articles in fact I'm using the custom converts discuessed @ mkyong's site. What I'm asking is the converter found in the managed bean that Forge creates when you issue a "scaffold from-entities" command in Forge.
Example:
In the SAKILA database, there's a table called Actor. So using Forge I created an entity, then scaffolded it.
Here's a snippet of the converter
public Converter getConverter()
{
return new Converter()
{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value)
{
return ActorBean.this.entityManager.find(Actor.class, Long.valueOf(value));
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value)
{
if (value == null)
{
return "";
}
return String.valueOf(((Actor) value).getActorId());
}
};
}
I can I use this code in my JSF page to convert an Object to a String?
Thanks for your patience. I've also attached the managedBean that Forge generated.
-
ActorBean.java.zip 2.0 KB
-
-
4. Re: How to use converters
lincolnthree Jul 8, 2012 5:08 PM (in response to g00gle88)Try it see if it works. I don't see why it shouldn't.