1 Reply Latest reply on Nov 4, 2010 9:25 AM by Michael Angelo

    Richfaces + Spring seems to cause null @Autowired properties

    Michael Angelo Newbie

      I am in a bind in a big way because this problem seems so obscure. I began developing an application using Spring and IceFaces a few weeks ago. I wasn't having any of the issues that I am over the last few days trying to convert to RichFaces.

       

      Of course all of the backing Spring bean classes were moved right over. The proper adjustments were made in the web.xml file.

       

      Upon running may application I see a blank form with all of the drop down lists populated as expected. I put a break point in a custom converter for one of the drop downs. I put this breakpoint on the getAsString method. This method does not involved the @Autowired  property, but I can see the Spring correctly injected its value from within the debugger. All is good!!

       

      On the subsequent view I retrieve a row from the database. There are quite a few @Autowired properties that have been injected just fine. In the debugger I now have a breakpoint on the getAsObject method. Once the debugger stops there my @Autowired property that is nedded in this method is null.

       

      I cannot for the life of me see how moving to Richfaces could cause such a disaster, but I can't find anything thing else and am at my wits end!! I desperately want to move to RichFaces, but am in one hell of a bind!!!!

       

      Please help!!!

       

      Here is the custom converter bean:

       

      public

       

      class DocumentTypeConverter implements Converter {

       

       

      @Autowired

      DDocumentTypeDAO dao;

       

       

      @Override

       

      public Object getAsObject(FacesContext context, UIComponent ui, String id) {

       

      DDocumentType docType =

      dao.findById(id);

       

      return docType;

      }

       

       

      @Override

       

      public String getAsString(FacesContext context, UIComponent ui, Object obj) {

       

       

      if (obj == null) {

       

      return "";

      }

       

      DDocumentType dt = (DDocumentType)obj;

       

      return dt.getDctypeD();

      }

       

       

      public DDocumentTypeDAO getDao() {

       

      return dao;

      }

       

       

      public void setDao(DDocumentTypeDAO dao) {

       

      this.dao = dao;

      }

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • 1. Re: Richfaces + Spring seems to cause null @Autowired properties
          Michael Angelo Newbie

          I hope my experiences can help someone else that may encounter this problem. The issue was not RichFaces at all. With the help of Max Katz I figured out the issue. Mainly Max and his colleague did, but I'll share this with you.

           

          I was using Spring beans for everything "# { }" in my JSF / RichFaces pages, even jsf converters. Max suggested that I remove all RichFaces libraries and see if it still happened and it did. Somehow, IceFaces fixes this problem, but upon every request, the converter instance is recreated and doesn't get its properties injected by Spring. This is what was causing my DAO to be null.

           

          The only solution was to obtain the XmlWebApplicationContext from the ServletContext and get the DAO bean manually.

           

          Not too bad, but I'd surely like to know how ICE addressed this issue. Maybe JSF 2 or beyond will fix this. I have not tested with JSF 2 so maybe it already is fixed.

           

          MIke