Hi Jean-Baptiste,
>
> This doesn't sound right to me at all.
> I've always relied on the presence of the input field to perform
validation or not,
> and I think it's far more easier to switch validation on or off by setting
this
> entry rather than to do it in the code, using the mapping and or request.
This is
> just declarative vs programmative.
>
> Here's a typical usecase I have that, if I'm not missing something, would
have to
> be modified if you made such a change:
> - The user clicks on a link to change his personal information
> - The action is configured with an actionForm, but without input, so that
the
> action can have access to the form, retrieve the info from the database,
populate
> the form, and forward to a JSP page. At this step, the form is empty, or
just
> contains the key of the user we're interested in.
> - The user modifies the information and submits the form. This action is
configured
> to use the same form class, but now has an input parameter, so that the
information
> the user submits is now validated.
>
> This design is used in a lot of cases, and I don't understand how
validating the
> form even if the input parameter is not there would help us, and I don't
see what
> it would add.
>
> Am I missing something?
Now I understand the underlying problem, and I think I have reported some
origins of it in my other messages on design with Struts.
With version 0.5, one can decide easily if he wanted or not validation to
occurs in the ActionForm: you only had to choose between ActionForm or
ValidatingActionForm interfaces.
With version 1.0, the two interfaces where merged in a single class
ActionForm, and there was no simple way to discriminate between validation
or not, apart from assigning a value to the "input" attribute.
So the problem is really, when Struts decides (on what criterium) to call
the validate function of ActionForm? Either programmative or declarative...
With my design to group under one action corelated subactions, perhaps I
have selected the wrong way to use Struts. To reproduce your use case:
- The ActionForm is first called on a URL like "doSomething.do?action=Init".
- Based on the request parameter (or the ActionForm property "action", if
you defined it), I can decide to retrieve info from the database but to to
abort the validation, even if the "input" attribute is defined.
- Then I forward to "edit" that present a JSP page to the user.
- When the user submit the form, I come back on the URL
"doSomething.do?action=Valid". Taking the action request, I can decide to
validate the whole form and redirect to the "input" page if an error occurs.
As my design seems to be the *bad* one, I think I will have to change my
code (explode my actions in struts-config.xml to create action
/doSomethingInit and /doSomethingValid, and attach an "input" value only to
/doSomethingValid, change all my JSP forms with these URL, and in the move
suppress the now unused "action" parameter...). And Craig will have to
rollback the CVS :,-(
Am I alone to have fallen in that trap?
Pierre M�tras