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 10:18:05 GMT
Regarding:


2011/12/1 Josep García <jgarcia@isigma.es>

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

The validation requires getters/setters on the action, and does not pickup
values from submitted input form params. Am I right?
Maybe, the ValueStack should also contain submitted params.

Cheers,
Josep

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message