1 Reply Latest reply on Jun 22, 2010 5:23 PM by Andreas Haumer

    Pojo can't be injected to Converter class

    Fabin Riako Newbie
      Hi All

      I am trying to create a create a Converter class for my SelectOneMenu. I created DbUtil calss for all database access. But I can't inject the DbUtil to my Converter class. Can anybody help me to solve this.

      Here is the sample code


      @Name("dBUtil")
      public class DBUtil {
           
           @In
           EntityManager entityManager;
           
           @Logger
           Log log;
           
           public Location findLocationById(String locationId)
           {
                return entityManager.find(Location.class,Integer.valueOf(locationId));
           }
      }


      @Name("locationConverter")
      @Converter
      @BypassInterceptors
      public class LocationConverter implements javax.faces.convert.Converter {     
           
           @In(create=true)
           DBUtil dbUtil;
           
           public Object getAsObject(FacesContext context, UIComponent component, String value) {
                if(dbUtil==null)
                     System.out.println("dbUtil==null");
                if((value!=null) && !value.toString().equals("--Select--"))
                     return dbUtil.findLocationById(value);
                else
                     return null;
           }

           public String getAsString(FacesContext context, UIComponent component, Object value) {          
                return value!=null && ! value.toString().equals("")  ? ((Location)value).toString() : null;          
           }

      }