This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes Issue: commandButton's onsucess attribute not working as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Issue: commandButton Watch "Issue: commandButton New topic
Author

Issue: commandButton's onsucess attribute not working as expected

Mark Donalds
Greenhorn

Joined: Oct 10, 2011
Posts: 1
Hi,

I'm new to JSF and I'm having the following issue:

I'm writing a page to add a new user to the database. This is what it is supposed to do: let the user fill in the fields, validate entered values and if no errors (by errors I understand wrong values in fields, i.e. a number in a name field, or missing values when required) were found then it should prompt the user asking him whether he or she actually wants to add this info to the database, if yes: proceed and add user to the DB, otherwise, do nothing. The thing is that no matter whether errors were found or not, it always asks the user if he or she wants to add the user to the database, which it should not do if errors were found.

I'm using the commandButton's attribute onsucess to do this, but I'm not sure if this is the intended use for it. It would be nice if any of you could tell me what I'm doing wrong or what I should do instead to achieve what I want.

Here's my code:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="./recursos/plantillas/general.xhtml">

<ui:define name="head">
<!--<link href="./recursos/css/formulario_personalizado.css" type="text/css" rel="stylesheet" />-->
<title>Captura de datos personales de usuario</title>
</ui:define>

<ui:define name="top">
<h2>Captura de datos personales de usuario</h2>
</ui:define>

<ui:define name="content">
<h:form>

<p:panel id="panelInfoPersonal" header="Información personal">
<p:messages />
<h:panelGrid columns="3">
<h:outputLabel id="etiquetaNombre" for="entradaNombre" value="Nombre(s):"></h:outputLabel>
<p:inputText id="entradaNombre" required="true" value="#{directorioUsuarios.usuario.nombre}" requiredMessage="Su nombre es requerido"></p:inputText>
<p:message for="entradaNombre"/>

<h: outputLabel id="etiquetaApellidoPaterno" for="entradaApellidoPaterno" value="Apellido paterno:"></h:outputLabel>
<p:inputText id="entradaApellidoPaterno" required="true" value="#{directorioUsuarios.usuario.apellidoPaterno}" requiredMessage="Su apellido paterno es requerido"></p:inputText>
<p:message for="entradaApellidoPaterno" />

<h: outputLabel id="etiquetaApellidoMaterno" for="entradaApellidoMaterno" value="Apellido materno:"></h:outputLabel>
<p:inputText id="entradaApellidoMaterno" required="true" value="#{directorioUsuarios.usuario.apellidoMaterno}" requiredMessage="Su apellido materno es requerido"></p:inputText>
<p:message for="entradaApellidoMaterno" />

<h: outputLabel id="etiquetaFechaNacimiento" for="entradaFechaNacimiento" value="Fecha de nacimiento:"></h:outputLabel>
<p:calendar id="entradaFechaNacimiento" value="#{directorioUsuarios.usuario.fechaNacimiento}" navigator="true" effect="slideDown" yearRange="1900:2000" required="true" requiredMessage="Su fecha de nacimiento es requerida"/>
<p:message for="entradaFechaNacimiento"/>

<h:outputLabel id="etiquetaCorreoElectronico" for="entradaCorreoElectronico" value="Correo electrónico:"></h:outputLabel>
<p:inputText id="entradaCorreoElectronico" required="true" value="#{directorioUsuarios.usuario.correoElectronico}" requiredMessage="Su correo electrónico es requerido">
<f:validator validatorId="mx.udg.sit.utileria.validador.EmailValidator" />
</p:inputText>
<p:message for="entradaCorreoElectronico" />
</h:panelGrid>
<p:commandButton value="Guardar" update="panelInfoPersonal" onsuccess="confirmation.show()" />
</p:panel>

<p:confirmDialog message="Esta seguro que desea agregar a este usuario?"
showEffect="bounce" hideEffect="explode"
header="Agregar nuevo usuario" severity="alert" widgetVar="confirmation">

<p:commandButton value="Sí" update="messages" oncomplete="confirmation.hide()"
actionListener="#{directorioUsuarios.guardaUsuario}" />
<p:commandButton value="No" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>

</h:form>
</ui:define>
<ui:define name="bottom"></ui:define>
</ui:composition>
</html>


Thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Issue: commandButton's onsucess attribute not working as expected
 
Similar Threads
multiple form in xhtml page nad update different controlls on two different forms
Trouble updating primefaces component w/ajax
Updating a form in primefaces when a selection is made in the datatable
SelectOneMenu - Validation Error: Value is not valid
primefaces command button is not working