Return-Path: X-Original-To: apmail-struts-user-archive@www.apache.org Delivered-To: apmail-struts-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8C2307B64 for ; Thu, 1 Dec 2011 09:47:54 +0000 (UTC) Received: (qmail 87931 invoked by uid 500); 1 Dec 2011 09:47:52 -0000 Delivered-To: apmail-struts-user-archive@struts.apache.org Received: (qmail 87736 invoked by uid 500); 1 Dec 2011 09:47:51 -0000 Mailing-List: contact user-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list user@struts.apache.org Received: (qmail 87711 invoked by uid 99); 1 Dec 2011 09:47:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2011 09:47:51 +0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=HTML_IMAGE_ONLY_28,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL,T_REMOTE_IMAGE X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.210.176] (HELO mail-iy0-f176.google.com) (209.85.210.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2011 09:47:45 +0000 Received: by iagk10 with SMTP id k10so3047903iag.35 for ; Thu, 01 Dec 2011 01:47:23 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.24.160 with SMTP id v32mr1660160ibb.45.1322732841780; Thu, 01 Dec 2011 01:47:21 -0800 (PST) Received: by 10.50.106.131 with HTTP; Thu, 1 Dec 2011 01:47:21 -0800 (PST) In-Reply-To: References: Date: Thu, 1 Dec 2011 10:47:21 +0100 Message-ID: Subject: Re: using xwork validator programatically? From: =?UTF-8?Q?Josep_Garc=C3=ADa?= To: Struts Users Mailing List , lukasz.lenart@gmail.com Content-Type: multipart/mixed; boundary=00151773d9942ac6cf04b304bd01 X-Virus-Checked: Checked by ClamAV on apache.org --00151773d9942ac6cf04b304bd01 Content-Type: multipart/alternative; boundary=00151773d9942ac6c904b304bdff --00151773d9942ac6c904b304bdff Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Basically, validatorKey build from clazz AND context. final String validatorKey =3D buildValidatorKey(clazz, context); I enclose a patch, with changes relative to xwork-core-2.1.6. In order to validate dynamic form input fields (based on freemarker's ability to render input fields from xml tree), I've also had to code my own field validator, because my action does not have getter/setter for the dynamic fields. In my derived XmlRequiredFieldValidator, I reimplement getFieldValue: protected Object getFieldValue(String name, Object object) throws ValidationException { ValidateableXml action =3D (ValidateableXml) object; Map params =3D action.getParameterMap(); String[] val =3D params.get(name); String str =3D null; if (val !=3D null) { str =3D val[0]; if (str.isEmpty()) { str =3D null; } } return str; } I fear I'll probably have to rewrite xml*fieldvalidator for other validator types. If you can think of a better alternative, let me know. Cheers, Josep 2011/11/30 =C5=81ukasz Lenart > 2011/11/30 Josep Garc=C3=ADa > > > This way, it works, but the downside: 149 line source file to work arou= nd > > the problem. > > > > Could you prepare a patch and label it with 3.x ? Maybe we'll be able to > refactor the manager with your changes > > > Kind regards > -- > =C5=81ukasz > + 48 606 323 122 http://www.lenart.org.pl/ > Warszawa JUG conference - Confitura http://confitura.pl/ > --00151773d9942ac6c904b304bdff Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Basically,=C2=A0 validatorKey build from clazz AND context.

=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 final String validatorKey =3D buildVal= idatorKey(clazz, context);

I enclose a patch, with changes relative = to xwork-core-2.1.6.


In order to validate dynamic form input fie= lds (based on freemarker's ability to render input fields from xml tree= ), I've also had to code my own field validator, because my action does= not have getter/setter for the dynamic fields.

In my derived XmlRequiredFieldValidator, I reimplement getFieldValue:
=C2=A0=C2=A0=C2=A0 protected Object getFieldValue(String name, Object= object) throws ValidationException {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 ValidateableXml action =3D (ValidateableXml) object;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Map<String, String[]> para= ms =3D action.getParameterMap();
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 String[] val =3D params.get(name);
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 String str =3D null;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 if (val !=3D null) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 str =3D val[0];
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (str.isEmpty()) {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 str =3D null;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return str;
=C2=A0=C2=A0= =C2=A0 }

I fear I'll probably have to rewrite xml*fieldvalidator for other v= alidator types.

If you can think of a better alternative, let me kno= w.

Cheers,
Josep

2011/11/30 =C5= =81ukasz Lenart <lukasz.lenart@googlemail.com>
2011/11/30 Josep Garc=C3= =ADa <jgarcia@isigma.es>

> This way, it works, but the downside: 149 line source file to work aro= und
> the problem.
>

Could you prepare a patch and label it with 3.x ? Maybe we'll be = able to
refactor the manager with your changes


Kind regards
--
=C5=81ukasz
+ 48 606 = 323 122=C2=A0ht= tp://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

--00151773d9942ac6c904b304bdff-- --00151773d9942ac6cf04b304bd01 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@struts.apache.org For additional commands, e-mail: user-help@struts.apache.org --00151773d9942ac6cf04b304bd01--