4 Replies Latest reply on Aug 17, 2012 8:30 AM by Rafael Jurado

    object data empty in long running conversation

    Rafael Jurado Newbie

      Hi all,

       

      I´m new in the forum. I´m learning Seam 2 for my own. I´m trying to build a very simple application to learn about conversations. I´m doing a simple 2 step wizard to store an entity in the database. In the first step the user can enter data. In step two data inserted in step one is show and user can cancel or confirm the store operation. When user enter in step 1 a long-running conversation is started.

       

      Step 1 xhtml

      <h:form id="reservarPaso1Form">
      
              <rich:panel>
                  <f:facet name="header">Paso 1</f:facet>
      
                  <s:decorate id="fechaEntradaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha entrada</ui:define>
                      <rich:calendar id="fechaEntrada"
                             required="true"
                                value="#{nuevaReserva.fechaEntrada}" datePattern="MM/dd/yyyy" />
                  </s:decorate>
      
      
                  <s:decorate id="fechaSalidaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha salida</ui:define>
                      <rich:calendar id="fechaSalida"
                                value="#{nuevaReserva.fechaSalida}" datePattern="MM/dd/yyyy" />
                  </s:decorate>
           
           </rich:panel>
      
           <div class="actionButtons">
                  <s:button id="cancelar" value="Cancelar" view="/home.xhtml" propagation="end"/>
                  <s:button id="siguiente" value="Siguiente" view="/reservarPaso2.xhtml"/>
           </div>
      
      </h:form>
      

       

       

      Users should hit in 'Siguiente' button to go to step2 page.

      s:button tag should store nuevaReserva object in conversation context and propagate it.

       

      Step 2 xhtml

       

      <h:form id="reservarPaso2Form">
      
              <rich:panel>
                  <f:facet name="header">Paso 2</f:facet>
      
                   <s:decorate id="fechaEntradaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha entrada</ui:define>
                      <rich:calendar id="fechaEntrada"
                             required="true"
                                value="#{nuevaReserva.fechaEntrada}" datePattern="MM/dd/yyyy" />
                  </s:decorate>
      
      
                  <s:decorate id="fechaSalidaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha salida</ui:define>
                      <rich:calendar id="fechaSalida"
                                value="#{nuevaReserva.fechaSalida}" datePattern="MM/dd/yyyy" />
                  </s:decorate>
      
              </rich:panel>
      
              <div class="actionButtons">
                  <s:button id="confirmar" value="Confirmar" view="/home.xhtml" action="#{realizarReserva.confirmar}"/>
                  <s:button id="cancelar" value="Cancelar" view="/home.xhtml" propagation="end"/>
              </div>
      
          </h:form>
      

       

       

      The problem is page 2 fields are blank when plage is shown. In Jboss Seam Debug Page I can see nuevaReserva object but attributes are empty. What am I doing wrong?

       

      nuevaReserva entity

       

      @Entity
      @Name("nuevaReserva")
      public class Reserva implements Serializable
      {
      
          private Long id;
          
          private Date fechaEntrada;
          private Date fechaSalida;
      
      .......
      }
      

       

       

       

      Thanks is advance.

        • 1. Re: object data empty in long running conversation
          Mehmet Ali Karabulut Newbie

          1. Is your "RealizarReserva" EJB stateful? (ie annotated as @Stateful)

          2. What's the scope of this bean? Should be at least Conversation(default if not scope is defined) or Session.

          3. Do you inject and outject your entity instance properly in this bean? The correct way to do this is shown below:

          @Out(required=false)

          @In(required=false)

          private NuevaReserva nuevaReserva;

           

          Hope this helps,

          Cheers

          • 2. Re: object data empty in long running conversation
            Rafael Jurado Newbie

            Hi Mehmet, thanks for reply.

             

            1. I´m using POJOs instead of EJBs. The class RealizarReserva is not annotated with a scope tag.

            2. I think default scope is Conversation for action beans.

            3. I do inject and outject with:

             

            @In @Out 
            private Reserva nuevaReserva;
            

             

            Note:

             

            A workaround I have discovered is that if I use:

             

            <s:button id="siguiente" value="Siguiente" view="/bookStep2.xhtml"/>
            

             

            the data is not shown in page 2, but If I use:

             

            <h:commandButton action="#{realizarReserva.goToStep2()}" value="Siguiente"/>
            

             

            public String goToStep2() {                                             
                    return "/bookStep2.xhtml";        
            }
            

             

            the data is shown is page 2. It´s a ugly workaround. The reason I have found is <s:button> doesn´t make a POST. I don´t know if exists an easier way of doing.

             

            <h:commandButton view="/bookStep2.xhtml" value="Siguiente"/> <!-- This doesn´t work -->
            

             

            Thanks.

            • 3. Re: object data empty in long running conversation
              Mehmet Ali Karabulut Newbie

              Hi,

              Since <s:button> does not submit the form, the data entered in the form is not binded to the entity yet. You have to post the data to see in the next page.

              Your solution is correct.

              It's not ugly,but perhaps it may look better in the following way.

              Instead of writing an action method, you can just define a jsf navigation to the next page:

               

              <h:commandButton action="step2" value="Siguiente"/>

               

              and define "step2" navigation case in the page.xml file of step1.

               

              bookStep1.page.xml:

              <navigation>

                  <rule if-outcome="step2">

                    <redirect view-id="/bookStep2.xhtml"/>

                  </rule>

              </navigation>

               

              Cheers,

              • 4. Re: object data empty in long running conversation
                Rafael Jurado Newbie

                I have tried the outcome with action attribute in commandButton and it works perfect! I think is a more clean solution. Now I can remove goToStep2() method from realizarReserva bean. Its only function was redirect to page 2.

                 

                Thank you so much for your help!