I would suggest using the MultiActionController which does have support for binding request params to Command objects if the delegate methods have a command object parameter (this appears to be an undocumented feature but a nice one!)
You would have to create a new resolver to deal with the multi-submit buttons. i would suggest this:
Code:
public class SubmitParameterPropertiesMethodNameResolver implements
MethodNameResolver {
private Properties mappings;
/**
* Set URL to method name mappings from a Properties object.
* @param mappings properties with URL as key and method name as value
*/
public void setMappings(Properties mappings) {
this.mappings = mappings;
}
public void afterPropertiesSet() {
if (this.mappings == null || this.mappings.isEmpty()) {
throw new IllegalArgumentException("'mappings' property is required");
}
}
public String getHandlerMethodName(HttpServletRequest request)
throws NoSuchRequestHandlingMethodException {
for (Iterator it = this.mappings.keySet().iterator(); it.hasNext();) {
String submitParamter = (String) it.next();
if (WebUtils.hasSubmitParameter(request, submitParamter)) {
return (String) this.mappings.get(submitParamter);
}
}
return null;
}
which would map from a properties file of _addOrganisation=methodName
where the button name="_addOrganisation" (or "_addOrganisation.x) for image buttons.
But the multi-action does binds but doesnt do errors natively.
whats really needed is a MultiActionFormController
which at its simplest could be a little like this
Code:
public abstract class SimpleMultiActionFormController extends SimpleFormController {
private MethodNameResolver methodNameResolver = new InternalPathMethodNameResolver();
public final void setMethodNameResolver(MethodNameResolver methodNameResolver) {
this.methodNameResolver = methodNameResolver;
}
public final MethodNameResolver getMethodNameResolver() {
return this.methodNameResolver;
}
protected ModelAndView processFormSubmission(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (errors.hasErrors() || isFormChangeRequest(request)) {
if (logger.isDebugEnabled()) {
logger.debug("Data binding errors: " + errors.getErrorCount());
}
return showForm(request, response, errors);
}
else {
String methodName = this.methodNameResolver.getHandlerMethodName(request);
Method m = (Method) this.getClass().getMethod(methodName,
new Class[] {Object.class,
BindException.class});
if (m == null) {
throw new NoSuchRequestHandlingMethodException(methodName, getClass());
}
List params = new ArrayList(2);
params.add(command);
params.add(errors);
return (ModelAndView) m.invoke(this, params.toArray(new Object[params.size()]));
}
}
}
which using the above methodname resolver would resolve to subclass methods such as
addOrganisation(Object command, BindException errors) throws Exception
addCapability(Object command, BindException errors) throws Exception
finalSubmit(Object command, BindException errors) throws Exception
hope this helps
DISCLAIMER: no idea if this code works as i havnt tested it. -Stuart