Madhav Bhargava wrote:
Hi All,
I have a JSP page where on the select of a radio button some controls are
disabled/enabled. The form bean associated with this JSP extends
ValidatorForm. I have created rules in validation-xml for each of these
controls which are there on the screen. One rule that is common to all the
controls is -"required".
Depending on the selection of the radio button different methods in a
DispatchAction class are called. If i need to do server side validations
then how can i prevent the validator framework to validate controls which
have been disabled.
For client side validations i can just do some slight modifications in
validation-rules.xml and get the behavior i want.
For server side validations of this kind i can think of the following:
1. Override the apache class that provides the "required" behavior, then
change validator-rules.xml to have the custom class instead.
2. override the validate method in the form bean and based on the request
attributes get only errors for the controls that are enabled. - Somehow this
method though simple fix does not appeal to me much.
What can be the best way in which this can be acheived.
One more thing:
Does struts provide you a way in which you can check in a form bean whether
a control was disabled. The behavior that i observed is that if the control
is disabled then the value in the form bean is null. Which is also the case
when the user does not enter anything in the control.
That's correct, and is standard HTML/HTTP behaviour. You can do two
things to meet your requirements:
- write your validation rules with 'validwhen' instead of 'required', if
there's a way you can describe when a field should be required or not in
a validwhen rule
- write separate sets of validation rules for each use case
The latter is easiest if you have different action mapping paths for
each use case. You probably don't since you mentioned DispatchAction.
But you should be able to use the dispatch method param as the control
variable in your validwhen rules, as in
(*this* == null) or (method='some-action-method-that-requires-this)
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]