Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
2003.10.30 - Thank you for struts-resumeHi 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 This is part of action.BaseForm
/**
* An overridden validate method which attempts to bypass
* validation.
* <div id="caution_overridden_validate" title="Overridden Validate">
* Due to a bug (or unintended feature) in struts, as
* explained in
* <a href="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16401">this bu
g report</a>
* its difficult (or impossible) when using the Validator with
* LookupDispatchAction to bypass validation on a method level
* without employing JavaScript. I thought it would be nice to have
* a cancel method with no dependency on JavaScript which was able
* to bypass validation. Hence, in this class we override the
* validate method and look for the parameter name (e.g., action) and
* its value (e.g., Cancel) and if the cancel button was pressed,
* the call to super.validate is bypassed.
* <a href="http://www.mail-archive.com/[email protected]/msg60
169.html">Initial report</a>
* by Matt Raible on struts-user mailing list.
* Follow up
* <a href="http://www.mail-archive.com/[email protected]/msg129
62.html">1</a>
* and
* <a href="http://www.mail-archive.com/[email protected]/msg129
66.html">2</a>
* by Brandon Goodin on struts-dev mailing list.
* </div>
*
* @param mapping The <code>ActionMapping</code> used to select this
* instance
* @param request The servlet request we are processing
*
* @return <code>ActionErrors</code> object that encapsulates any
* validation errors
*/
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? Regards,
|
||||||