Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Issue: commandButton Watch "Issue: commandButton New topic

Issue: commandButton's onsucess attribute not working as expected

Mark Donalds

Joined: Oct 10, 2011
Posts: 1

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" "">

<html xmlns=""

<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 name="top">
<h2>Captura de datos personales de usuario</h2>

<ui:define name="content">

<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:message for="entradaCorreoElectronico" />
<p:commandButton value="Guardar" update="panelInfoPersonal" onsuccess="" />

<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" />

<ui:define name="bottom"></ui:define>

Thanks in advance
I agree. Here's the link:
subject: Issue: commandButton's onsucess attribute not working as expected
It's not a secret anymore!