1 Reply Latest reply on Oct 12, 2010 12:11 AM by gaborj

    Ajax requests and Beans in EVENT Scope

    uesker

      Hi!!


      I´m facing a problem with a Bean with EVENT Scope and Ajax Request.


      What I need it´s to fill a text area and press a button that fill a data table with the value from text area. So, I created a method that its call by a ajax component (command button). I can enter inseide the method but the value of bean binding to text area it´s null. It´s happens only when I´m working with the Bean on EVENT scope. If I remove the Scope annotation, the value of bean it´s present, but I don´t want to do this.


      Here is the xhtml page



      <rich:panel>
                   <f:facet name="header">#{messages['srprocess.fillIdentification.page.title']}</f:facet>
                     <h:outputText value="#{messages['srprocess.fillIdentification.page.description']}"/><br/>
                  <rich:spacer height="20px"/>
                  
                  <s:decorate id="campoTitulo" template="/layout/fields.xhtml">
                       <ui:define name="label">#{messages['srprocess.fillIdentification.page.titleofsr']}"</ui:define>
                       <h:inputTextarea rows="3" cols="100" value="#{srProtocol.title}"/>
                  </s:decorate>
                  
                  <s:decorate id="campoInstituicao" template="/layout/fields.xhtml">
                       <ui:define name="label">#{messages['srprocess.fillIdentification.page.institution']}"</ui:define>
                       <h:inputTextarea rows="3" cols="100" value="#{srProtocol.institution}"/><br/>
                  </s:decorate>
                  
                  <s:decorate id="campoAutores" template="/layout/fields.xhtml">
                       <ui:define name="label">#{messages['srprocess.fillIdentification.page.authors']}</ui:define>
                       <h:inputTextarea rows="3" cols="100" value="#{srProtocol.authors}"/>     
                  </s:decorate>
                  
                  <s:decorate id="campoContato" template="/layout/fields.xhtml">
                       <ui:define name="label">#{messages['srprocess.fillIdentification.page.contact']}</ui:define>
                       <h:inputTextarea rows="3" cols="100" value="#{srProtocol.contact}"/>     
                  </s:decorate>
                  
                  
                  <s:decorate id="campoData" template="/layout/fields.xhtml">
                       <ui:define name="label">#{messages['srprocess.fillIdentification.page.date']}</ui:define>
                       <rich:calendar value="#{srProtocol.date}" />     
                  </s:decorate>
                  
                  <div style="clear:both"/>
                  
              </rich:panel>
      



      And the Bean whitout Scope annotation on SecondaryQuestion variable



      @Name("secondaryQuestionAction")
      @Scope(ScopeType.PAGE)
      public class SecondaryQuestionAction implements Serializable {
      
           
           private static final long serialVersionUID = 8394705048656015853L;
           
           @In
           private StatusMessages statusMessages;
           
           @In(required=false)
           @Out(scope=ScopeType.BUSINESS_PROCESS, required=false)
           protected SRProtocol srProtocol;
           
           @In(required=false)
           private SecondaryQuestion secondaryQuestion;
           
           private List<SecondaryQuestion> secondaryQuestionList;
           
           @Logger
           private Log log;
           
           public SecondaryQuestion getSecondaryQuestion() {
                return secondaryQuestion;
           }
      
           public void setSecondaryQuestion(SecondaryQuestion secondaryQuestion) {
                this.secondaryQuestion = secondaryQuestion;
           }
      
           public boolean isExibeTabelaQuestoes() {
                return (secondaryQuestionList.size() > 0);
           }
      
           public List<SecondaryQuestion> getSecondaryQuestionList() {
                return secondaryQuestionList;
           }
      
           public void setSecondaryQuestionList(
                     List<SecondaryQuestion> secondaryQuestionList) {
                this.secondaryQuestionList = secondaryQuestionList;
           }
      
           @BeginTask
           public void startFillSecondaryQuestion() {
                if (secondaryQuestionList == null) {
                     secondaryQuestionList = new ArrayList<SecondaryQuestion>();
                     statusMessages.addFromResourceBundle("task.initiated.message");
                }
           }
           
           @EndTask
           public String endFillSecondaryQuestion() {
                if (srProtocol != null) {
                     srProtocol.setSecundaryQuestionList(secondaryQuestionList);
                }
                statusMessages.addFromResourceBundle("srprocess.fillsecondaryquestion.page.success");
                return "/listarTarefas.xhtml";
           }
           
           public void addSecondaryQuestion(ActionEvent event) {
                if (secondaryQuestion != null && secondaryQuestion.getQuestion() != null) {
                     secondaryQuestionList.add(secondaryQuestion);
                     secondaryQuestion = null;
                } else {
                     statusMessages.addFromResourceBundle("srprocess.fillsecondaryquestion.page.question.empty");
                }
           }
           
           public void removeQuestion(SecondaryQuestion secondaryQuestion) {
                secondaryQuestionList.remove(secondaryQuestion);
           }
      }
      



      Thanks for the help!



        • 1. Re: Ajax requests and Beans in EVENT Scope
          gaborj

          Actually, this is the normal behavior. This scope is nothing to do with jBPM events or Seam Events...  EVENT scope is:


          Analogous to the servlet request scope. Exists from the beginning of the Restore View phase until the end of the Render Response phase in the JSF life cycle or until a redi- rect occurs.


          You can use e.g. lifecycle methods @Create @Destroy and logs to monitor if your bean is there...


          Why is that you need EVENT scope here?