You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thompson Marzagao <th...@nettheory.com> on 2004/10/20 20:03:00 UTC

Struts Validator and dynamically generated form fields

Hi all,

I am generating some form field names dynamically, based on the value of 
a request variable. Since I am using Niall Pemberton's 
LazyValidatorActionForm (see http://www.niallp.pwp.blueyonder.co.uk/), I 
don't have a problem getting their values. The problem is validating them.

Currently I have to specify in the validation.xml file all fields that I 
want validated. Since I am generating some form fields on the fly, I 
can't hardcode their names in the validation.xml file.

Does anybody know of a way around this? I guess I could always extend 
the LazyValidatorActionForm class with my own implementation of the 
validate method, but does anybody have a better way, so I can still have 
all my validation specified inside the validation.xml file?

Thanks,
Thompson


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


Re: Struts Validator and dynamically generated form fields

Posted by dmu2201 <dm...@mail.ikasths.dk>.
Thompson Marzagao wrote:

> Hi all,
>
> I am generating some form field names dynamically, based on the value 
> of a request variable. Since I am using Niall Pemberton's 
> LazyValidatorActionForm (see http://www.niallp.pwp.blueyonder.co.uk/), 
> I don't have a problem getting their values. The problem is validating 
> them.
>
> Currently I have to specify in the validation.xml file all fields that 
> I want validated. Since I am generating some form fields on the fly, I 
> can't hardcode their names in the validation.xml file.
>
> Does anybody know of a way around this? I guess I could always extend 
> the LazyValidatorActionForm class with my own implementation of the 
> validate method, but does anybody have a better way, so I can still 
> have all my validation specified inside the validation.xml file?
>
> Thanks,
> Thompson
>
Is the forms dynamic in a way that the names of the fields is also 
changing, or is the field names the same?! If they are then you can 
specify them in struts-config.xml as form-beans with properties, but of 
course, then all of the validation rules would have to have the same 
parameters each time. In my project the change each time so I had to 
write the validate(...) method myself, but did it in a way where the 
validation logic, the classes that perform the actually validation, was 
external, so they could be reused.

I guess the ultimative workaround would be a code-generator that wrote 
the struts-config and the validation config on the fly ;-)

Claus

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