1 Reply Latest reply on Oct 21, 2009 10:02 AM by Nikolay Elenkov

    Stateless component null?

    Ypatios Asmanidis Newbie

      Hi i have one stateless and one stateful bean ... my stateless bean is :

      public class SchedJobAction implements SchedJob{
              private Log log;
              @In QuartzTriggerHandle timer;
              public void scheduleAlert(@Expiration Date when,
                              @IntervalDuration Long interval,
                              @FinalExpiration Date endDate) {
                      log.info("working now");
              public void testMethod() {
                      log.info("test method ok");

      my stateful bean is

      public class testJobAction implements testJob {
              private Log log;
              SchedJobAction processor;
              @Remove @Destroy
              public void destroy() {
                      // TODO Auto-generated method stub
              public void startJob() {
                      // TODO Auto-generated method stub
                      log.info("hi there");
                      Calendar cal = Calendar.getInstance ();
                      cal.set (209, Calendar.OCTOBER, 21);
                      //SchedJobAction processor=new SchedJobAction();

      when the startJob method is called I get the following exception

              ... 93 more
      Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection: testJobAction.processor on: panda.test.testJobAction with value: class org.javassist.tmp.java.lang.Object_$$_javassist_seam_4
              at org.jboss.seam.util.Reflections.set(Reflections.java:86)
              at org.jboss.seam.Component.setFieldValue(Component.java:1923)
              ... 121 more
      Caused by: java.lang.IllegalArgumentException
              at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
              at java.lang.reflect.Field.set(Field.java:657)
              at org.jboss.seam.util.Reflections.set(Reflections.java:71)
              ... 122 more
      09:58:14,362 WARN  [lifecycle] #{testJobAction.startJob}: javax.ejb.EJBTransactionRolledbackException: could not set field value: testJobAction.processor
      javax.faces.FacesException: #{testJobAction.startJob}: javax.ejb.EJBTransactionRolledbackException: could not set field value: testJobAction.processor
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
              at javax.faces.component.UICommand.broadcast(UICommand.java:387)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)

      If I remove the

       @In SchedJobAction processor 

      and just insert

      SchedJobAction processor=new SchedJobAction() 

      then when the processor.testMethod() is called, the timer and log are both null...what am I doing wrong?

        • 1. Re: Stateless component null?
          Nikolay Elenkov Master

          Since SchedJobAction is an SLSB, you need to use the interface when injecting.
          The value that gets injected is a proxy and is not an instance of SchedJobAction (Cf. class org.javassist.tmp.java.lang.Object_$$_javassist_seam_4), but is an instance of SchedJob

          So use:

          SchedJob processor;

          If you want to use Seam features (injection, etc), you should not instantiate with new.
          Use Component.getInstance(), @Autocreate or @In(create=true) instead.