3 Replies Latest reply on Aug 27, 2008 10:10 AM by blabno

    h:commandButton submit the form but don´t execute the action method

    maykell.mflores.uci.cu

      Hi all, i have the following issue:
      I have i simple Seam gen application, which have a select page and a detail page, the last one is also the add page.
      When i enter a new element in the detail page (perform an add operation), the program render the same page but depending of one condition shows an add button or an update button, an ordinary situation. The problem is that when i add a new element and immediately afterwards i try to update the element clicking on the update button this submit the form but don´t execute the action method, it is a strange behavior.
      To make this button work i have to go the List page pick the element recently added and only in this way the update button works.


      Thanks in advance,
      Maykell.


      This is my code:
      The List Page



      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich" 
              template="layout/template.xhtml">
      
              <ui:define name="body">
      
          <h:messages globalOnly="true" styleClass="message"/>
      
                      <rich:panel>
                              <f:facet name="header">Listado de Testigos para el expediente actual</f:facet>
      
                              <div class="results">
                                  <h:outputText value="No existen testigos para este expediente" 
                                    rendered="#{listaTestigos.size == 0}"  /> 
                                      <h:dataTable
                                      id="testigoList" var="testigo" value="#{listaTestigos}"
                                      rendered="#{listaTestigos.size != 0}" cellpadding="2" rowClasses="graybg,whitebg">
                                      <h:column>
                                              <f:facet name="header">CI</f:facet>
                          #{testigo.ci}
                      </h:column>
      
                                      <h:column>
                                              <f:facet name="header">Nombre</f:facet>
                          <s:link id="nombreLink" value="#{testigo.nombre}" view="/testigo.xhtml" propagation="join" />
                      </h:column>
      
                                      <h:column>
                                              <f:facet name="header">direccion</f:facet>
                          #{testigo.direccionParticular}
                      </h:column>
      
                              </h:dataTable></div>
                  <div style="clear:both"/>
      
                      </rich:panel>
      
                      <div class="actionButtons"><s:button id="done"
                              value="Create testigo" view="/testigo.xhtml" /></div>
      
              </ui:define>
      
      </ui:composition>
      






      The Detail page:



      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:s="http://jboss.com/products/seam/taglib"
              xmlns:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:rich="http://richfaces.org/rich"
              xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
      
              <ui:define name="body"> 
      
          <h:messages globalOnly="true" styleClass="message"/>
      
                      <h:form id="registertestigoActionForm">
                              <rich:panel>
                                      <f:facet name="header">Registrar testigo</f:facet>
      
                                      <s:decorate id="ciDecoration" template="layout/edit.xhtml">
                                              <ui:define name="label">CI</ui:define>
                                              <h:inputText id="name" required="true" value="#{testigoAction.testigo.ci}" />
                                      </s:decorate>
      
                                      <s:decorate id="nombreDecoration" template="layout/edit.xhtml">
                                              <ui:define name="label">Nombre</ui:define>
                                              <h:inputText id="nombre" required="true" value="#{testigoAction.testigo.nombre}" />
                                      </s:decorate>
      
                                      <s:decorate id="direcionDecorate" template="layout/edit.xhtml">
                                              <ui:define name="label">Direccion</ui:define>
                                              <h:inputText id="direccion" value="#{testigoAction.testigo.direccionParticular}" />
                                      </s:decorate>
      
                                      <s:decorate id="declaracionDecorate" template="layout/edit.xhtml">
                                              <ui:define name="label">Declaracion</ui:define>
                                              <h:inputTextarea id="declaracion" value="#{testigoAction.testigo.declaracion}"
                                                      cols="60" rows="15" />
                                      </s:decorate>
      
                                      <div style="clear: both" />
      
                              </rich:panel>
      
                              <div class="actionButtons"><h:commandButton
                                      id="registertestigo" value="Registrar testigo"
                                      action="#{testigoAction.registerTestigo}"
                                      rendered="#{testigo.ci == null}">
                              </h:commandButton> 
                              <h:commandButton id="actualizatestigo" value="Actualizar testigo"
                                      action="#{testigoAction.updateTestigo}" immediate="true"
                                      rendered="#{testigo.ci != null}">
                              </h:commandButton> 
                              <s:button propagation="end" id="done" value="Done"
                                      view="/testigoList.xhtml"  /></div>
                      </h:form>
              </ui:define>
      </ui:composition>
      





      The action class:




      package com.prueba.facade;
      
      import java.util.List;
      
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.Component;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.Transactional;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.core.Events;
      import org.jboss.seam.faces.FacesMessages;
      
      import com.prueba.domain.Acusado;
      import com.prueba.domain.Testigo;
      
      @Name("testigoAction")
      @Scope(ScopeType.CONVERSATION)
      public class TestigoAction {
      
              @In EntityManager entityManager;
              @In FacesMessages facesMessages;
              
              @DataModel
              List<Testigo> listaTestigos ;
              
              @DataModelSelection
              @Out(required = false) @In(required = false) 
              Testigo testigo; 
              
              public Testigo getTestigo() {
                      return testigo;
              }
      
              public void setTestigo(Testigo testigo) {
                      this.testigo = testigo;
              }
      
              @Factory("listaTestigos")
              public void loadListaTestigos()
              {
                      listaTestigos = entityManager.createQuery("from Testigo").getResultList();
                      if (listaTestigos.isEmpty() )
                      Events.instance().raiseTransactionSuccessEvent("EntidadCRUD","No existen testigos registrados para el expediente actual", "TestigoAction.loadListaTestigo()");
      
              }
      
              @Transactional
              public void registerTestigo() {
                      entityManager.persist(testigo);
                      this.testigo = testigo;
                      Events.instance().raiseTransactionSuccessEvent("EntidadCRUD","Testigo Registrado", "TestigoAction.registerTestigo");
              }
      
              @Transactional
              public void updateTestigo() {
                      entityManager.flush();
                      Events.instance().raiseTransactionSuccessEvent("EntidadCRUD","Testigo Actualizado", "TestigoAction.updateTestigo");
              }
      
      }







        • 1. Re: h:commandButton submit the form but don´t execute the action method
          blabno

          I'd say that when you click on the list you join (or start) conversation thus when you are on details page you are in conversation. When you click on the Create testigo button you do not join nor start any conversation thus your TestigoAction bean does not have anything to persist nor update.
          Try adding join="true" to your Create testigo button.

          • 2. Re: h:commandButton submit the form but don´t execute the action method
            maykell.mflores.uci.cu

            Hi Bernard, thanks for your replay, with your answer i have several doubts suddenly.


            I used to think that when i opened a conversation in one page to the next page, (in this case list page to go to detail page) all the beans of the detail page were carried off by the conversation, in this case the TestigoAction bean and testigo bean begin to form part of the same conversation. Thus every bean backing a jsf or seam UIComponent and every action bean bound to those UIComponent when are invoked have to run under the boundaries of the conversation recently opened in the last page.
            ¿it is that correct?
            ¿why i have to join to the conversation in every button i touch?


            Now, the behavior i refer to in my first post i think don´t have to be concerned with the behavior of conversations, it is simply a button that when it is clicked don´t execute the action that is attached to it.
            ¿this behavior is related to conversation management?
            ¿this behavior is some kind of bug in JSF or Seam?



            Thank you very much,

            • 3. Re: h:commandButton submit the form but don´t execute the action method
              blabno

              Put logging instructions in your action method that you think is not invoked and you will see that it is.


              Scenario 1 : Register testigo


              When you are on List Page your are not in a long-running conversation. When you hit Create testigo button you do not start nor join conversation. So all beans and data you enter last only for one request. When you fill data on Detail page and press Registrar testigo button you still are not in a long-running conversation, so new object is created and displayed on the Detail page. That object (testigoAction) exists only in that request. In next one, when you press Actualizar testigo button, it is created again without any data from previous request. This is because you do not start long-runnig conversation at any point.


              Scenario 2 : Select testigo from list


              When you click on the s:link from the list you join (and if it does not exist then start) long-running conversation. Now all the beans and data stay between requests and thus you can press Update, Register and so on and you still see the data.