3 Replies Latest reply on Mar 31, 2008 8:29 AM by blabno

    DataTable selected object and its presence in context

    blabno

      I've noticed strange bahavior of dataTable selected object and its presence in context. I have two pageflows browseCountries and editCountry. The latter is subflow. When I am on countriesList.xhtml page (browseCountries pageflow), and click on a country from dataTable to edit it a new subflow is started - the editCountry pageflow. I want to display data of selected country there, but there is nothing in a context.
      However if I add following code to editCountry pageflow definition the selected country gets injected into bean's attribute and outjected into context, and thus available on editCountry.xhtml page.


      <start-state>
         <transition to="editForm">
            <action expression="#{countryManager.init}"/>
         </transition>
      </start-state>



      Could anybody explain why is this happening ? Why is selected country available only for bean and not directly on the page if bean is not touched ?


      I attach code of my beans, jPDL's and xhtml's for reference. They are of course trimmed to show only what is important.



      <pageflow-definition name="browseCountries">
      
          <start-page name="countriesList" view-id="/countriesList.xhtml">
              <transition name="edit" to="editCountry"/>
          </start-page>
      
          <process-state name="editCountry">        
              <sub-process name="editCountry"/>     
              <transition to="countriesList"/>
          </process-state>
         
      </pageflow-definition>



      <pageflow-definition name="editCountry">
          
          <start-state>
              <transition to="editForm">
                  <action expression="#{countryManager.init}"/>
              </transition>
          </start-state>
          
          ...
      </pageflow-definition>



      countriesList.xhtml


      <h:dataTable value="#{countries}" var="country">
         <h:column>
            <h:selectBooleanCheckbox value="#{countryBrowser.selectedCountries[country]}"/>
         </h:column>
         <h:column>
            <h:commandLink action="edit" value="#{country.name}"/>
         </h:column>
      </h:dataTable>



      editCountry.xhtml


      <h:form>
         <h:outputText value="#{messages.countryName}"/>
         <h:inputText value="#{country.name}"/>
      </h:form>



      ManageCountryActionBean.java


      @Stateful
      @Name("countryManager")
      public class ManageCountryActionBean implements ManageCountryAction {
          @In(value = "country", create = true)
          @Out(value = "country")
          private Country country;
      
          /**
           * Initiates bean attributes.
           * Method should be called from pageflow descriptor.
           */
          public void init() {}
      }

        • 1. Re: DataTable selected object and its presence in context
          pmuir

          Is countryManager used before you start the sub process?

          • 2. Re: DataTable selected object and its presence in context
            dan.j.allen

            A data model selection is a request-scoped context variable. If you don't promote it to the conversation context, then it will not be able to live beyond a redirect, which is what I believe is happening in your page flow. The init() method is essentially promoting its scope so that it can be available.


            Even if no redirect is occurring (and I am somehow wrong), you most certainly want the country to be in the conversation context anyway for the purpose of editing.

            • 3. Re: DataTable selected object and its presence in context
              blabno

              Pete, as I wrote above : Why is selected country available only for bean and not directly on the page if bean is not touched ? The countryManager is not used before start of subprocess.


              Dan, great answear, that explains it. I understand now that when entering subflow, a new request is started. I thought that it was still same request.