2003.10.30 - Thank you for struts-resume#
Hi Matt,
Kudos on your excellent work on appfuse and struts-resume. Since, I've been using appfuse and struts-resume to gather a basic understanding of struts and "helper" technologies, its time to give back a little.
I ran into the same problem as yourself, as per your email
. So, I followed the email thread and wasn't quite happy with the JavaScript solution. So, I conjured a non-JavaScript solution which is posted below. Be aware that my struts understanding is fairly rudimentary and this might be a classic example of too much blending of V into the C from the MVC model.
This is part of action.BaseForm
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// Identify the request parameter containing the method name
String parameter = mapping.getParameter();
if( parameter != null ) {
// Identify the method name to be dispatched to.
String name = request.getParameter(parameter);
MessageResources resources =
(MessageResources) request.getAttribute(Globals.MESSAGES_KEY);
// Identify the localized message for the cancel button
String message = resources.getMessage("button.cancel");
// if message resource matches the cancel button then no
// need to validate
if( name != null && name.equals(message) ) {
if( log.isDebugEnabled() ) {
log.debug(mapping.getAttribute() + " '" + name +
"' method, so no need to validate");
return null;
}
}
}
// perform regular validation
return super.validate(mapping, request);
}
What do you think of this approach?