views:

33

answers:

0

Hello,

my question is about programming best practice when using the Struts Validator Plugin.

I have a form containing many fields, some of which have to be validated on submission through the Struts plug-in, and some must not be validated.

As a new user to this, I thought it would be good to use the special tags provided by Struts for every field (e.g. html:text instead of input type="text").

When testing my JSP page, I found out that fields declared using the special Struts tags have to be defined in the properties of the form bean, otherwise an exception is thrown.

So I have two solutions here : either use the custom Struts tag for all the fields, and define them all in the Struts config file (which is a little silly IMO), or use the normal tags for fields that won't have to be Struts-Validated (which is messy in the code).

Both approaches are not making me happy, as for the first one, I have to do useless work (and if I'd add new fields later, even if those must not be checked, I'd have to change the configuration file as well). For the second one, the code is getting ugly, since sometimes you will see an input type="text", and sometimes an html:text, just because it has to be validated or not.

So my question is : is there a better way to handle this situation ? If not, which of the two solutions is recommended and why ?

Best regards,

Nils

P.S.: I suppose that asking such questions is not a problem on this site, if it's not the case please let me know, I know it could seem a little stupid, but this is really important to me for the sake of doing the things the way they are supposed to be done.