12 Replies Latest reply on Jan 28, 2011 2:44 AM by pawel.gutowski

    Annotated @In value is not injected into the stateful session bean

    pawel.gutowski

      Seam is not injecting @In value into my stateful session bean (it always equals null):


      @Stateful
      @Scope(SESSION)
      @Name("mypanel")
      public class MyPanelBean implements Serializable, MyPanel{
          @In(value="val",create=true,required=false)
          @Out(value="val",scope=ScopeType.SESSION)
          private String val;
              
          public String getVal() {
              log.info("========= getting val: " + val);
                  return val;
          }
              
          public void setVal(String val) {
              this.val = val;
              log.info("========= setting val: " + val);
          }
              
          @Factory("val")
          public void initVal(){
              val = "initial value";
              log.info("========== val should have been initialized...");
          }
      (...)
      }
      



      ... and the log:



      10:29:11,183 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
      10:29:11,185 WARN [InterceptorsFactory] EJBTHREE-1246: Do not use InterceptorsFactory with a ManagedObjectAdvisor, InterceptorRegistry should be used via the bean container
      10:29:11,199 INFO [MyPanelBean] ========== val should have been initialized...
      10:29:11,200 INFO [MyPanelBean] ========== val should have been initialized...
      10:29:11,218 ERROR [TxPolicy] javax.ejb.EJBTransactionRolledbackException: @Out attribute requires non-null value: mypanel.val
      10:29:11,226 SEVERE [lifecycle] JSF1054: (Phase ID: RENDER_RESPONSE 6, View ID: /myPanel.jsp) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@1280059]
      10:29:11,258 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      org.jboss.seam.RequiredException: @Out attribute requires non-null value: mypanel.val
      



      I have already tried every combination:




      • With/without the initVal() method

      • With/witout value="val" for both: @In and @Out

      • required=true/false for both: @In and @Out

      • create=true/false for @In

      • With/without scope=ScopeType.SESSION



      When I try this:



          @In(create=true,required=false)
          @Out(required=false)
          private String val;
          
          @Factory("val")
          public void initVal(){
              val = "initial value";
              log.info("========== val should have been initialized...");
          }
      



      ...and this in my view:



      <h:inputText id="testVal" value="#{mypanel.val}"/>
      



      ... then form can be submitted without any errors, but val always equals null.
      It is not injected!
      Even the setVal() method is not called! (There is no line in log file saying this)


      My configuration:



      • Seam 2.2.0.GA

      • JBoss AS 5.1.0.GA

        • 1. Re: Annotated @In value is not injected into the stateful session bean
          aareshchanka

          Is your MyPanelBean instantiated? If so you you should see info about component creation in logs at startup.


          Are getters\setters declared in interface?


          You should declare destroy method in interfaces and in implementation mark with annotation @Remove, @Destroy


          Try to Add @Autocreate annotation to MyPanelBean.


          Try



          private String val = "";




          • 2. Re: Annotated @In value is not injected into the stateful session bean
            pawel.gutowski

            Alexandr Areshchanka wrote on Jan 25, 2011 10:31:


            Is your MyPanelBean instantiated? If so you you should see info about component creation in logs at startup.

            I think so, this is the log filtered by MyPanelBean:


            16:59:41,923 INFO [JBossASKernel] installing bean: jboss.j2ee:ear=jboss-seam-jbpm.ear,jar=jboss-seam-jbpm.jar,name=MyPanelBean,service=EJB3
            16:59:41,924 INFO [JBossASKernel] jndi:jboss-seam-jbpm/MyPanelBean/local-org.gutek.example.jbpm.MyPanel
            16:59:41,924 INFO [JBossASKernel] jndi:jboss-seam-jbpm/MyPanelBean/remote
            16:59:41,924 INFO [JBossASKernel] jndi:jboss-seam-jbpm/MyPanelBean/local
            16:59:41,924 INFO [JBossASKernel] Added bean(jboss.j2ee:ear=jboss-seam-jbpm.ear,jar=jboss-seam-jbpm.jar,name=MyPanelBean,service=EJB3) to KernelDeployment of: jboss-seam-jbpm.jar
            16:59:42,106 INFO [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@118f455{name=jboss.j2ee:ear=jboss-seam-jbpm.ear,jar=jboss-seam-jbpm.jar,name=MyPanelBean,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}
            16:59:42,168 INFO [SessionSpecContainer] Starting jboss.j2ee:ear=jboss-seam-jbpm.ear,jar=jboss-seam-jbpm.jar,name=MyPanelBean,service=EJB3
            16:59:42,169 INFO [EJBContainer] STARTED EJB: org.gutek.example.jbpm.MyPanelBean ejbName: MyPanelBean
             jboss-seam-jbpm/MyPanelBean/local - EJB3.x Default Local Business Interface
             jboss-seam-jbpm/MyPanelBean/local-org.gutek.example.jbpm.MyPanel - EJB3.x Local Business Interface
            16:59:44,226 INFO [Component] Component: mypanel, scope: SESSION, type: STATEFUL_SESSION_BEAN, class: org.gutek.example.jbpm.MyPanelBean, JNDI: jboss-seam-jbpm/MyPanelBean/local
            17:01:37,933 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,934 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,944 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,945 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,960 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,961 INFO [MyPanelBean] ========== val should have been initialized...
            17:01:37,963 INFO [MyPanelBean] ========== val should have been initialized...
            



            I tried all of your suggestions - no result :(

            • 3. Re: Annotated @In value is not injected into the stateful session bean
              aareshchanka

              hm.. very strange,


              mayby exception occurs because you are using same names in



              @Factory("val")



              and




              @Out(value="val",scope=ScopeType.SESSION)



              try to remove one and use it on the page just like val



              <h:inputText id="testVal" value="#{val}"/>






              • 4. Re: Annotated @In value is not injected into the stateful session bean
                pawel.gutowski

                With this combination:


                @In(value="val",create=true,required=false)
                @Out(required=false)
                private String val;
                
                @Factory(value="val")
                public void initVal(){
                    this.val = "initial value";
                    log.info("========== val should have been initialized... [" + this.val + "] myPanelBean: " + this);
                }
                



                ...and the view:


                <h:inputText id="testVal" value="#{val}"/>
                



                "initial value" is visible in the input when the form is rendered. But when I type there something alse and submit the form, then I see in logs that my value hasn't been changed and still equals "initial value".
                When I change annotation into this:


                @In(create=true,required=false)
                


                then behaviour doesn't change.


                I have also noticed that my setter and getter are never called.

                • 5. Re: Annotated @In value is not injected into the stateful session bean
                  monkeyden

                  There are a few things I see here.  First, it doesn't make sense to inject AND bind the field to the backing bean.  Second, as I recall:


                  @In(....,required=false)
                  



                  says null is OK, so ignore the @Factory.  Third, @In won't work on a request parameter.  Roll back to the your original example for the view part.  Try removing @In and @Out from the instance variable and bind it using:


                  <h:inputText id="testVal" value="#{mypanel.val}"/>
                  



                  ....then let us know what happens.

                  • 6. Re: Annotated @In value is not injected into the stateful session bean
                    pawel.gutowski

                    I removed @In and @Out annotation and rolled back to the previous binding in my view:


                    <h:inputText id="testVal" value="#{mypanel.val}"/>
                    


                    ... and tried it with and without @Factory annotation.
                    In both cases:



                    • getter is called while rendering form and returns null (null at this moment is OK, as I haven't instantiated this value before)

                    • after typing some text into the input and submitting form, setter is not called. Val still equals null.

                    • If I instantiate value, like this:



                    private String val = "initial value";
                    


                    ...then I see it in the rendered form, but after submitting, setter is also not called (val still equals "initial value").

                    • 7. Re: Annotated @In value is not injected into the stateful session bean
                      monkeyden

                      Post your xhtml and MyPanel src.

                      • 8. Re: Annotated @In value is not injected into the stateful session bean
                        pawel.gutowski

                        They are VERY VERY messy, as I am making first steps with Seam and testing also other things in that files...


                        MyPanelBean:


                        package org.gutek.example.jbpm;
                        
                        import java.io.Serializable;
                        import java.util.ArrayList;
                        import java.util.List;
                        import java.util.Map;
                        import java.util.Set;
                        
                        import javax.naming.InitialContext;
                        
                        import javax.ejb.Remove;
                        import javax.ejb.Stateful;
                        
                        import org.jboss.seam.ScopeType;
                        import org.jboss.seam.annotations.AutoCreate;
                        import org.jboss.seam.annotations.Create;
                        import org.jboss.seam.annotations.Destroy;
                        import org.jboss.seam.annotations.Factory;
                        import org.jboss.seam.annotations.In;
                        import org.jboss.seam.annotations.Scope;
                        import org.jboss.seam.annotations.Logger;
                        import org.jboss.seam.annotations.Name;
                        import org.jboss.seam.annotations.Out;
                        import org.jboss.seam.annotations.datamodel.DataModel;
                        import org.jboss.seam.annotations.datamodel.DataModelSelection;
                        
                        import static org.jboss.seam.ScopeType.SESSION;
                        
                        import org.jboss.seam.log.Log;
                        import org.jbpm.api.ExecutionService;
                        import org.jbpm.api.ProcessEngine;
                        import org.jbpm.api.TaskService;
                        import org.jbpm.api.task.Task;
                        
                        @Stateful
                        @Scope(SESSION)
                        @Name("mypanel")
                        @AutoCreate
                        public class MyPanelBean implements Serializable, MyPanel{
                             
                             @Logger
                             private static Log log; // Dla beanow Entity i Stateful, logger musi byc static! Jesli nie to NPE!  
                        
                             
                             @In(required=false)
                             @Out(required=false)
                             private UserChoice userChoice;
                        
                             @DataModel
                             private List<Task> personalTasks;
                        /*
                             @DataModel
                             private List<Task> groupTasks;
                        */
                             @DataModelSelection
                             @Out(required=false)
                             private Task task;
                             
                             @In(required=false)
                             @Out(required=false)
                             private Map<String, Object> processVariables;
                             
                             /*
                             @In(create=true)
                             @Out
                             private TaskBean taskstate;
                             */
                             
                             //@In(value="val",create=true,required=false)
                             //@Out(required=false)
                             private String val ="blablabla";
                             
                             public String getVal() {
                                  log.info("========= getting val: " + this.val + " myPanelBean: " + this);
                                  return this.val;
                             }
                             
                             public void setVal(String val) {
                                  this.val = val;
                                  log.info("========= setting val: " + val + " myPanelBean: " + this);
                             }
                             
                             //@Factory(value="val")
                             public void initVal(){
                                  this.val = "initial value";
                                  log.info("========== val should have been initialized... [" + this.val + "] myPanelBean: " + this);
                             }
                             
                             /*
                             @Create  
                             @Override  
                             public void init() {  
                                 this.val = "XYZ-777";  
                             } 
                             */
                             
                             public void relogin(){
                                  if( userChoice != null){
                                       log.debug("========== Przelogowany na: " + userChoice.getLabel());
                                       refreshTaskList();
                                  }
                             }
                             
                             @Factory("personalTasks")
                             public void refreshTaskList(){
                                  if(userChoice != null){
                                       log.debug("====== szukam prywatnych taskow dla usera: " +userChoice.toString());
                                       ProcessEngine engine = JBPMFacade.getProcessEngine();
                                       log.debug("======= mam silnik: " + engine);
                                       TaskService taskService = engine.getTaskService();
                                       log.debug("======= mam taskService: " + taskService);
                                       personalTasks = taskService.findPersonalTasks(userChoice.toString()); 
                                       log.debug("====== znalazlem taski: " + personalTasks);
                                  }else{
                                       personalTasks = new ArrayList<Task>();
                                  }
                             }
                             
                                  
                             public void runNewProcess(){
                                       ProcessEngine engine = JBPMFacade.getProcessEngine();
                                       log.info("======= mam silnik: " + engine);
                                       ExecutionService executionService = engine.getExecutionService();
                                       log.info("======= mam executionService: " + executionService);
                                       executionService.startProcessInstanceByKey("myprocess");
                                       log.info("======= proces odpalony");
                                       refreshTaskList();
                             }
                                  
                             public String editTask(){
                                  if(task != null){
                                       log.info("============ Wybrano zadanie: " + task.getId());
                                       Set<String> processVarNames = JBPMFacade.getProcessEngine().getExecutionService().getVariableNames(task.getExecutionId());
                                       processVariables = JBPMFacade.getProcessEngine().getExecutionService().getVariables(task.getExecutionId(), processVarNames);
                                       return task.getFormResourceName();
                                  } else{
                                       log.warn("============ wybrany TaskBean == null !!!");
                                  }
                                  return null;
                             }
                             
                        
                             public String finishTask(){
                                  log.info("============ Rozpoczynam przepychanie Tasku dalej...");
                                  String execId = task.getExecutionId();
                                  JBPMFacade.getProcessEngine().getExecutionService().signalExecutionById(execId);
                                  log.info("============ Task przepchniety :)");
                                  refreshTaskList();
                                  return "/myPanel.jsp";
                             }
                             
                             public String saveAndFinishTask(){
                                  // TODO: Zmienne z formularza chyba sie same zdjely?
                                  log.info("======== Zmienne zdjete z formularza? : " + processVariables );
                                  log.info("======== val : " + this.val);
                                  return finishTask();
                             }
                        
                             public UserChoice getUserChoice() {
                                  return userChoice;
                             }
                        
                             public void setUserChoice(UserChoice userChoice) {
                        
                                  this.userChoice = userChoice;
                             }
                             
                             public Map<String, Object> getProcessVariables() {
                                  return processVariables;
                             }
                        
                             public void setProcessVariables(Map<String, Object> processVariables) {
                                  this.processVariables = processVariables;
                             }
                        
                             @Remove @Destroy
                                public void destroy() {}
                             
                             public enum UserChoice {
                        
                                  AAA("User A"), 
                                  BBB("User B"),
                                  CCC("User C"), 
                                  DDD("User D"), 
                                  EEE("User E"),
                                  FFF("User F");
                        
                                  private String label;
                        
                                  UserChoice(String label) {
                                       this.label = label;
                                  }
                        
                                  public String getLabel() {
                                       return label;
                                  }
                             }
                        }
                        
                        



                        ... and the view:


                        <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                        <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                        <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s"%>
                        <html>
                        <head>
                             <link href="/seam-jbpm/styles.css" rel="stylesheet" type="text/css" />
                             <!-- TABS-LIB START -->
                             <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
                             <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
                             <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
                             <script>
                                  $(document).ready(function() {
                                       $("#tabs").tabs();
                                  });
                             </script>
                             <!-- TABS-LIB END -->
                          
                        </head>
                          <body>
                          <f:view>
                            
                            <!--<form action="${form.action}" method="POST" enctype="multipart/form-data">-->
                            <h:form id="taskform">
                                 <h1>Szczegoly sprawy nr: ${process_id}</h1>
                                 <br/><br/>
                                 <h:inputText id="testVal" value="#{mypanel.val}"/>
                                  <table>
                                       <tr>
                                            <td>aaa</td>
                                            <td><select name="business_type"><option value="operation">Operacja</option></select></td>
                                            <td>bbb</td>
                                            <td><h:inputText id="policy_id" value="#{mypanel.processVariables.policy_id}"/><a href="#" onclick="alert('TODO: okienko dialogowe do wyszukiwania numeru polisy');">...</a></td>
                                       </tr>
                                       <tr>
                                            <td>ccc</td>
                                            <td><select name="business_area">
                                                      <option value="eee">ddd</option>
                                                      <option value="fff">ggg</option></select>
                                            </td>
                                            <td>hhh</td>
                                            <td><input type="text" name="proposal_id" /><a href="#" onclick="alert('TODO: okienko dialogowe do wyszukiwania numeru wniosku');">...</a></td>
                                       </tr>
                                       <tr>
                                            <td>iii</td>
                                            <td><select name="business_status">
                                                      <option value="jjj">W realizacji</option>
                                            </td>
                                            <td>kkk</td>
                                            <td><input type="text" name="pretension_id" /><a href="#" onclick="alert('TODO: okienko dialogowe');">...</a></td>
                                       </tr>
                                       <tr>
                                            <td>lll</td>
                                            <td><input type="text" name="business_priority" value="Wysoki" disabled="true" /></td>
                                            <td>Data</td>
                                            <td><input type="text" name="time_created_str" disabled="true" value="${time_created_str}" /></td>
                                       </tr>
                                       <tr>
                                            <td>mmm</td>
                                            <td><input type="text" name="business_owner" value="xxxxxxx" disabled="true" /></td>
                                            <td>nnn</td>
                                            <td><h:inputText id="business_created_by" value="#{mypanel.processVariables['business_created_by']}"/></td>
                                       </tr>
                                       <tr>
                                            <td>ooo</td>
                                            <td><input type="text" name="deadline_time_str" value="${deadline_time_str}" disabled="true" /></td>
                                            <td>ooo</td>
                                            <td><input type="text" name="time_last_modified_str" value="${time_last_modified_str}" disabled="true" /></td>
                                       </tr>
                                       <tr>
                                            <td></td>
                                            <td></td>
                                            <td>Uzytkownik modyfikujacy</td>
                                            <td><input type="text" name="modifying_user" value="zzzzzzz" disabled="true" /></td>
                                       </tr>
                                  </table>
                            
                             
                                  <div id="tabs">
                                       <ul>
                                            <li><a href="#tab_clients"><span>werewqr</span></a></li>
                                            <li><a href="#tab_contacts_hisotry"><span>rewqrewr</span></a></li>
                                            <li><a href="#tab_documents"><span>rewrewrew</span></a></li>
                                            <li><a href="#tab_required_documents"><span>grthgrt</span></a></li>
                                            <li><a href="#tab_task_list"><span>htrhtrh</span></a></li>
                                       </ul>
                                       <div id="tab_clients">
                                            <p>First tab is active by default:</p>
                                            <pre><code>$('#example').tabs();</code></pre>
                                       </div>
                                       <div id="tab_contacts_hisotry">
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                       </div>
                                       <div id="tab_documents">
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                       </div>
                                       <div id="tab_required_documents">
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                       </div>
                                       <div id="tab_task_list">
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                            Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
                                       </div>
                                  </div>  <!-- div id="tabs"--> 
                              
                             
                              <s:button action="#{mypanel.saveAndFinishTask}" value="Zapisz zmiany i zakoncz zadanie"/>
                              
                             </h:form>
                            <!--</form>-->
                            
                               </f:view>
                          </body>
                        </html>
                        

                        • 9. Re: Annotated @In value is not injected into the stateful session bean
                          monkeyden

                          and MyPanel (your interface) please

                          • 10. Re: Annotated @In value is not injected into the stateful session bean
                            pawel.gutowski

                            MyPanel.java:


                            package org.gutek.example.jbpm;
                            
                            import java.util.List;
                            import java.util.Map;
                            
                            import javax.ejb.Local;
                            
                            import org.jbpm.api.task.Task;
                            
                            import org.gutek.example.jbpm.MyPanelBean.UserChoice;
                            
                            @Local
                            public interface MyPanel {
                                 
                                 public void relogin();
                                 public void refreshTaskList();
                            
                                 public void runNewProcess();
                                 public String editTask();
                                 public String finishTask();
                                 public String saveAndFinishTask();
                            
                                 
                                 public Map<String, Object> getProcessVariables();
                                 public void setProcessVariables(Map<String, Object> processVariables);
                                 public String getVal();
                                 public void setVal(String val);
                                 public void initVal();
                                 
                                 public UserChoice getUserChoice();
                                 public void setUserChoice(UserChoice userChoice);
                            
                                 public void destroy();
                            }
                            

                            • 11. Re: Annotated @In value is not injected into the stateful session bean
                              monkeyden

                              I don't think s:button submits the form, to allow the value binding to happen.  Try replacing:


                              <s:button action="#{mypanel.saveAndFinishTask}" value="Zapisz zmiany i zakoncz zadanie"/>
                              



                              with:


                              <h:commandButton action="#{mypanel.saveAndFinishTask}" value="Zapisz zmiany i zakoncz zadanie"/>
                              


                              • 12. Re: Annotated @In value is not injected into the stateful session bean
                                pawel.gutowski

                                That was it!


                                Thank you! :)