You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Sayre <ri...@gmail.com> on 2007/07/14 13:18:08 UTC

Complex Validation

I am validating a form using the XML validate file.  The built in
validators are great for very basic validation but  I need to write a
validation too see if a value already exists in the database.  I am
not sure how to go about doing this.  All the validation examples I
found only show how to use the basic included validations.  Do I have
to write my own validator class that does the database check or is
there another method of validation I should be using?

Thank you,

Rich

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Complex Validation

Posted by Jorge Martín Cuervo <jo...@defactops.com>.
sorry, the code would be like:


ActionErrors errors = new ActionErrors();
errors.add(super.validate(mapping, request));


don't forget to add the errors from the commons validator.


El lun, 16-07-2007 a las 10:05 +0200, Jorge Martín Cuervo escribió:
> if you are not using dyna action forms, you can overwrite the method
> validate in the ActioForm bean. Or even extend this dyna validation
> action form and implemente your own validate like:
> 
> [...]
> public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
> 
> super.valudate(mapping, request);
> 
> ActionErrors errors = new ActionErrors();
> Locale locale = RequestUtils.getUserLocale(request, null);
> MessageResources resources = ((MessageResources)
> request.getAttribute(Globals.MESSAGES_KEY));
> 		
> 
> if (**your test**) {
> errors.add("**your field**", new
> ActionMessage("employer.requiredfield", 
> 		resources.getMessage(locale, "employer.orgName")));
> }
> 
> [...]
> 
> 
> El sáb, 14-07-2007 a las 07:48 -0330, Richard Sayre escribió:
> > I am validating a form using the XML validate file.  The built in
> > validators are great for very basic validation but  I need to write a
> > validation too see if a value already exists in the database.  I am
> > not sure how to go about doing this.  All the validation examples I
> > found only show how to use the basic included validations.  Do I have
> > to write my own validator class that does the database check or is
> > there another method of validation I should be using?
> > 
> > Thank you,
> > 
> > Rich
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
-- 
____________________________________
Jorge Martin Cuervo
 
Outsourcing Emarketplace
deFacto Powered by Standards
 
email <jo...@defactops.com>
voice +34 985 129 820
voice +34 660 026 384
____________________________________


DE FACTO STANDARDS, S.L., le informa que su dirección de correo
electrónico, así como el resto de los datos de carácter personal que
nos facilite, serán objeto de tratamiento automatizado en nuestros
ficheros, con la finalidad del envío de información comercial y/o
personal por vía electrónica. Vd. podrá en cualquier momento ejercer el
derecho de acceso, rectificación, cancelación y oposición en los
términos establecidos en la Ley Orgánica de Protección de Datos de
Carácter Personal (LOPD. 15/1999),  dirigiendo un escrito a C/
Gutiérrez Herrero (Centro De Empresas 'La Curtidora'), 52 - oficina 207
- 33402 AVILES (Asturias), o a nuestra dirección de correo electrónico
(info@defactops.com). También informamos que la información incluida en
este e-mail es CONFIDENCIAL, siendo para uso exclusivo del destinatario
arriba mencionado. Si Usted lee este mensaje y no es el destinatario
indicado, le informamos que está totalmente prohibida cualquier
utilización, divulgación, distribución y/o reproducción de esta
comunicación sin autorización expresa en virtud de la legislación
vigente.  Si ha recibido este mensaje por error, le rogamos nos lo
notifique inmediatamente por esta misma vía y proceda a su eliminación.

This e-mail contains information that will be added to our computerised
guest data base and will be trated in the strict confidence. If you
wish to access, correct, oppose or cancel your details, as specified
the Law 15/99, December 13th, please send a certified letter to this
effect to DE FACTO STANDARDS, S.L.., (C/ Gutiérrez Herrero (Centro De
Empresas 'La Curtidora'), 52 - oficina 207 33402 AVILES (Asturias)
SPAIN). If you read this message, and is not the destinatary, we
informal you that is forbidden anything utility, distribution,
divulgation or reproduction of this communication without express
authorization, of the present law.  If you received this message for
mistake, we proud in order to the present law, immediate communication
to us, and please erase this e-mail


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Complex Validation

Posted by Jorge Martín Cuervo <jo...@defactops.com>.
if you are not using dyna action forms, you can overwrite the method
validate in the ActioForm bean. Or even extend this dyna validation
action form and implemente your own validate like:

[...]
public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {

super.valudate(mapping, request);

ActionErrors errors = new ActionErrors();
Locale locale = RequestUtils.getUserLocale(request, null);
MessageResources resources = ((MessageResources)
request.getAttribute(Globals.MESSAGES_KEY));
		

if (**your test**) {
errors.add("**your field**", new
ActionMessage("employer.requiredfield", 
		resources.getMessage(locale, "employer.orgName")));
}

[...]


El sáb, 14-07-2007 a las 07:48 -0330, Richard Sayre escribió:
> I am validating a form using the XML validate file.  The built in
> validators are great for very basic validation but  I need to write a
> validation too see if a value already exists in the database.  I am
> not sure how to go about doing this.  All the validation examples I
> found only show how to use the basic included validations.  Do I have
> to write my own validator class that does the database check or is
> there another method of validation I should be using?
> 
> Thank you,
> 
> Rich
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
-- 
____________________________________
Jorge Martin Cuervo
 
Outsourcing Emarketplace
deFacto Powered by Standards
 
email <jo...@defactops.com>
voice +34 985 129 820
voice +34 660 026 384
____________________________________


DE FACTO STANDARDS, S.L., le informa que su dirección de correo
electrónico, así como el resto de los datos de carácter personal que
nos facilite, serán objeto de tratamiento automatizado en nuestros
ficheros, con la finalidad del envío de información comercial y/o
personal por vía electrónica. Vd. podrá en cualquier momento ejercer el
derecho de acceso, rectificación, cancelación y oposición en los
términos establecidos en la Ley Orgánica de Protección de Datos de
Carácter Personal (LOPD. 15/1999),  dirigiendo un escrito a C/
Gutiérrez Herrero (Centro De Empresas 'La Curtidora'), 52 - oficina 207
- 33402 AVILES (Asturias), o a nuestra dirección de correo electrónico
(info@defactops.com). También informamos que la información incluida en
este e-mail es CONFIDENCIAL, siendo para uso exclusivo del destinatario
arriba mencionado. Si Usted lee este mensaje y no es el destinatario
indicado, le informamos que está totalmente prohibida cualquier
utilización, divulgación, distribución y/o reproducción de esta
comunicación sin autorización expresa en virtud de la legislación
vigente.  Si ha recibido este mensaje por error, le rogamos nos lo
notifique inmediatamente por esta misma vía y proceda a su eliminación.

This e-mail contains information that will be added to our computerised
guest data base and will be trated in the strict confidence. If you
wish to access, correct, oppose or cancel your details, as specified
the Law 15/99, December 13th, please send a certified letter to this
effect to DE FACTO STANDARDS, S.L.., (C/ Gutiérrez Herrero (Centro De
Empresas 'La Curtidora'), 52 - oficina 207 33402 AVILES (Asturias)
SPAIN). If you read this message, and is not the destinatary, we
informal you that is forbidden anything utility, distribution,
divulgation or reproduction of this communication without express
authorization, of the present law.  If you received this message for
mistake, we proud in order to the present law, immediate communication
to us, and please erase this e-mail


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org