struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josep García <jgar...@isigma.es>
Subject Re: using xwork validator programatically?
Date Thu, 01 Dec 2011 09:47:21 GMT
Basically,  validatorKey build from clazz AND context.

        final String validatorKey = 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 = (ValidateableXml) object;
        Map<String, String[]> params = action.getParameterMap();
        String[] val = params.get(name);
        String str = null;
        if (val != null) {
            str = val[0];
            if (str.isEmpty()) {
                str = 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 Łukasz Lenart <lukasz.lenart@googlemail.com>

> 2011/11/30 Josep García <jgarcia@isigma.es>
>
> > This way, it works, but the downside: 149 line source file to work around
> > 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
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
> Warszawa JUG conference - Confitura http://confitura.pl/
>

Mime
View raw message