4 Replies Latest reply on Aug 31, 2007 8:26 AM by frippe

    Problems with converter

    frippe

      I'm part of a project using JBoss Seam as the main component and have been struggling to get a simple select-box to work.
      Pretty soon I've found out that a Converter was needed which ended up in the following solution:

      My conveter's interface

      @Local
      public interface MyConverter extends Converter {
      
      }


      My converter implementation

      @Stateless
      @Name("ConvertARO")
      public class AroConverter implements MyConverter {
      
       @PersistenceContext
       private EntityManager em;
      
       @Logger
       private Log log;
      
       public Object getAsObject(FacesContext ctx, UIComponent component, String value) {
       log.info("AroConverter:getAsObject() :: " + value);
       ARO aro = null;
       if ((value==null)||value.length()==0) {
       throw new ConverterException("Error 1 !");
       }
      
       for (Iterator iter = em.createQuery("from ARO").getResultList().iterator(); iter.hasNext();) {
       ARO a = (ARO) iter.next();
       if(a.getName().equals(value)){
       aro = a;
       break;
       }
       }
      
       if (aro==null) {
       aro = new ARO();
       aro.setAro_id(0);
       }
      
       log.info(aro);
       return aro;
       }
      
      
       public String getAsString(FacesContext ctx, UIComponent component, Object value) {
       if((ARO)value != null)
       return ((ARO)value).getName();
       else
       return "";
       }
      }


      Excerpt from my xhtml page

      <h:selectOneMenu id="selAro" value="#{selAcl.aro}" converter="#{ConvertARO}">
       <f:selectItems value="#{stockAction.axoRights}"/>
      </h:selectOneMenu>


      When I started working on this problem, I created the converter without the interface, which seemed to work. But sometimes JBoss freaks ut, telling me that the converter cannot be found when rendering. I solved that part with the interface. Now It renders OK, but when I try to submit information to an action class, JBoss gives me the error message: java.lang.ClassNotFoundException: No ClassLoaders found for: com.test.actions.MyConverter

      Why do I get this error?

      //Fredric