[
https://issues.apache.org/struts/browse/STR-3049?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41190
]
Niall Pemberton commented on STR-3049:
--------------------------------------
Yes it is possible - just means duplicating some of the "dispatch" logic in the
ActionForm.
ActionForm implementations which support Commons Validator have a
getValidationKey() method - so this can be used to hook into different
validation rules for dispatch style actions. So using the vanilla
"DispatchAction" as an example - if you wanted to say use a composite key (in
Commons Validator) of the ActionForm name plus the dispatch parameter - you
could do something like the following:
public class CustomerDispatchValidatorForm extends ValidatorForm {
public String getValidationKey(ActionMapping mapping, HttpServletRequest
request) {
String parameterName = mapping.getParameter();
String parameterValue = request.getParameter(parameterName);
String formName = mapping.getName();
return formName + "-" + parameterValue;
}
}
Then in your struts-config.xml....
<form-beans>
<form-bean name="customerForm"
type="mypackage.CustomerDispatchValidatorForm">
</form-beans>
<action path="/customer"
type="mypackage.CustomerDispatchAction"
name="customerForm"
validate="true"
parameter="method"
input="...">
<forward ... />
</action>
if the "method" parameter could be submitted with values "add", "update" and
"delete" - then in the validation.xml you would have forms with the following
keys:
<form-validation>
<formset>
<form name="customerForm-add">
</form>
<form name="customerForm-update">
</form>
<form name="customerForm-delete">
</form>
</formset>
</form-validation>
> Specifying Dispatcher based validations in validation.xml
> ---------------------------------------------------------
>
> Key: STR-3049
> URL: https://issues.apache.org/struts/browse/STR-3049
> Project: Struts 1
> Issue Type: Improvement
> Components: Core
> Environment: N/A
> Reporter: J Alex
>
> I want to confirm if there's a way to specify a mapping between the dispatch
> methods and the validations declaratively.
> The method should be independent of javascript.
> Scenario :
> Consider a single-page form (i.e single HTML <form> mapping to say
> /myAction.do ) with many sections, each section having its own Submit button.
> On submit of each, ONLY the fields within that section must be validated.
> Using DispatchAction to handle each submit button takes care of centralizing
> the handler methods and making the Action classes crisp. But, when it comes
> to validation, there's no way to specify in validation.xml the fields tied to
> a specific dispatch method.
> We could use the "page" parameter to delimit the validations, but this cannot
> be done declaratively since we cannot dynamically change the "page" using
> javascript on a particular submit. The workaround is to set validate=false,
> and explicitly invoke validation from the Action class after setting the
> "page" within each dispatcher method.
> i.e
> myForm.setPage(1);
> I think it will be a good enhancement to provide this mapping within Struts
> itself which i feel will greatly enhance the utility of DispatchAction.
> ActionMessages errors = myForm.validate( mapping, request );
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.