4 Replies Latest reply on Nov 14, 2005 8:43 AM by Udo Krass

    Conversation - how to start automatically with a given page

    Daniel Issa Newbie

      I have a Staful Session Bean with a method that starts a conversation
      scope:

      @Begin
      public String find() {
       report = null;
       String searchQuery = "from Report";
       reports = reportsDatabase.createQuery(searchQuery).getResultList();
       return "main";
      }
      


      I can now start a conversion from a view by calling this method
      from an action attribute, for example:
      <h:commandButton action="#{reportslist.find}" value="#{bundle.newreport}" />
      


      But I need to start the conversion scope always automatically when
      this page loads (not after pressing a button).

      Can anybody help me, please?
      Thanks a lot.

        • 1. Additionally info: Conversation - how to start automatically
          Daniel Issa Newbie

          For addition a source code from Stateful session bean and view page:

          Stateful bean:

          @Stateful
          @Name("reportslist")
          @Interceptor(SeamInterceptor.class)
          @Conversational(ifNotBegunOutcome="main")
          public class ReportsBO implements Reports, Serializable {
          
           @PersistenceContext(type=EXTENDED)
           private EntityManager reportsDatabase;
          
           @Out(required=false)
           private Report report;
          
           @DataModel
           private List<Report> reports;
           @DataModelSelectionIndex
           private int reportIndex;
          
           @Begin
           public String find() {
           report = null;
           String searchQuery = "from Report";
           reports = reportsDatabase.createQuery(searchQuery).getResultList();
           return "main";
           }
          
           public String editReport() {
           report = reports.get(reportIndex);
           return "edit_report";
           }
          
           public String newReport() {
           report = new Report();
           return "edit_report";
           }
          
           public String clearReports() {
           for (Report rep: reports) {
           reportsDatabase.remove(rep);
           }
           return "main";
           }
          
           @End
           public String confirmed() {
           if (report.getId()==0) reportsDatabase.persist(report);
           return "show_list";
           }
          
          }
          


          View:
          <%@ page contentType="text/html;charset=windows-1250" %>
          
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
          
          <HTML>
           <HEAD>
           <title>Report aplikace</title>
           </HEAD>
           <body bgcolor="white">
           <f:loadBundle basename="resources.Resources" var="bundle"/>
           <f:view>
           <h:form id="helloForm">
           <h:dataTable id="table"
           value="#{reports}"
           var="rep">
          
           <h:column>
           <f:facet name="header">
           <h:outputText value="#{bundle.name}"/>
           </f:facet>
           <h:outputText value="#{rep.name}"/>
           </h:column>
           <h:column>
           <h:outputText value="#{rep.id}"/>
           </h:column>
           <h:column>
           <h:commandButton action="#{reportslist.editReport}" value="Edit" />
           </h:column>
           </h:dataTable>
           <h:commandButton action="#{reportslist.newReport}" value="#{bundle.newreport}" />
           <h:commandButton action="#{reportslist.clearReports}" value="#{bundle.clear}" />
           </h:form>
           </f:view>
           </body>
          </HTML>
          


          And I simply need to start a new conversation scope always when this view loads (= start "find" method from the stateful bean always when this view loads).

          • 2. Re: Conversation - how to start automatically with a given p
            Rene Lavoie Newbie

            My *guess* is you want to try looking into @Create

            • 3. Re: Conversation - how to start automatically with a given p
              Gavin King Master

              Hmmmmmm, I have never tried to do this. Perhaps you could use @Intercept(ALWAYS), and add a method marked @Create @Begin to the bean. This should work, I guess...

              • 4. Re: Conversation - how to start automatically with a given p
                Udo Krass Newbie

                Hi issad,

                will this work for you?
                If yes, can you post your code?
                Thanks.

                Regards,

                Udo