[jboss-user] [JBoss Seam] - Custom JSF Converter???
nebukadnezzar
do-not-reply at jboss.com
Mon Sep 10 11:55:51 EDT 2007
Hi!
I'm trying to write a custom converter for passing my objects as GET-parameter...
But I still can't get them to work!
has anybody an example of doing this???
here's my code:
| @Name("categoryConverter")
| @Stateless
| public class CategoryConverterBean implements javax.faces.convert.Converter, CategoryConverter {
|
| @PersistenceContext
| private EntityManager entityManager;
|
| public Object getAsObject(FacesContext arg0, UIComponent arg1, String str)
| throws ConverterException {
| try {
| long id = Long.parseLong(str);
|
| return entityManager.createQuery("Select c from Category where c.id = :id")
| .setParameter("id", id)
| .getSingleResult();
|
| } catch (Exception e) {
| throw new ConverterException();
| }
|
| }
|
| public String getAsString(FacesContext arg0, UIComponent arg1, Object obj)
| throws ConverterException {
| if (obj instanceof Category) {
| return Long.toString(((Category)obj).getId());
| } else
| throw new ConverterException();
| }
|
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4082690#4082690
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4082690
More information about the jboss-user
mailing list