h:commandButton submit the form but don´t execute the action method
maykell.mflores.uci.cu Aug 25, 2008 5:43 PMHi 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"); } }