Hi Toll,
Your observation is correct. If you use LookupDispatchAction for creating
your own action class, and if you specify validate="true" in your
struts-config.xml then Struts will always validate the input regardless
which method in your action class is invoked.
One of the solution is to set validate="true" in the struts-config.xml and
ask Struts to perform or bypass the validation in your corresponding execute
methods in the action class. Like:
errors = form.validate(mapping, request);
if (!errors.isEmpty()) {
saveMessages(request, errors);
return new ActionForward(mapping.getInput());
}
I hope this will help you.
Moreover, try to avoid LookupDispatchAction because of the performance
issues in it because it creates a reverse map to lookup the method to
execute. Rather try to use the plain DispatchAction. It is just a suggestion
from my own experience.
Regards
Sujan
Sujan Deb
[EMAIL PROTECTED]
20 Dundas Street W, 6th Floor
Toronto, ON, Canada
416-861-5242
2-5242
-Original Message-
From: Toll, Marvin (M.) [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 25, 2005 11:01 AM
To: user@struts.apache.org
Subject: LookupDispatchAction : Cancel Button : html:cancel
It appears that extending LookupDispatchAction does *not* cause
validation to be bypassed when the following tag is used in a JSP:
Two Questions
1) Are we incorrect in our observation?
2) Does anyone have a better solution than the attached?
// Message for cancel button.
public static final String CANCEL_BUTTON_RESOURCE =
"common.button.cancel";
public static final String BACK_BUTTON_RESOURCE =
"common.button.back";
// LookupDispatchAction parameter name.
public static final String LOOKUP_DISPATCH_ACTION_PARAMETER =
"method";
/**
* This method is overridden to support page
* submission without validating in three specific contexts
* when the action class extends LookupDispatchAction.
* (1) A drop-down list box submitted via JavaScript
* whose selection is used to trigger initialization of other
attributes.
* (2) A cancel button was used for submission. (3) A back button
was
* used for submission.
*
* @param request The servlet request we are processing
* @param response The servlet response we are creating
* @param form The ActionForm instance we are populating
* @param mapping The ActionMapping we are using
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
protected boolean processValidate(
HttpServletRequest request,
HttpServletResponse response,
ActionForm form,
ActionMapping mapping)
throws IOException, ServletException {
String METHOD_NAME = "processValidate";
log.entering(CLASS_NAME, METHOD_NAME);
// Declaration.
boolean valid;
// Determine if LookupDispatchAction is being extended for this
request.
if (mapping.getParameter() != null
&& mapping.getParameter().equals(
Constants.LOOKUP_DISPATCH_ACTION_PARAMETER)) {
// Obtain the message resource bundle.
MessageResources messageResources =
this.getResources(request);
// Determine if a value has not been established in the
request object.
if (request
.getParameter(Constants.LOOKUP_DISPATCH_ACTION_PARAMETER)
== null) {
// Initialize the method name to be supported in a
LookupDispatchAction.
String[] methodName = { Constants.METHOD_RETURN_TO_PAGE
};
// Establish the default - supportable as a base class
method.
request.getParameterMap().put(
Constants.LOOKUP_DISPATCH_ACTION_PARAMETER,
methodName);
// Return without validating.
valid = true;
// Determine if the cancel or back button was selected.
} else if (
request.getParameter(
Constants.LOOKUP_DISPATCH_ACTION_PARAMETER).equals(
messageResources.getMessage(
Constants.CANCEL_BUTTON_RESOURCE))
|| request.getParameter(
Constants.LOOKUP_DISPATCH_ACTION_PARAMETER).equals(
messageResources.getMessage(
Constants.BACK_BUTTON_RESOURCE))) {
// Return without validating.
valid = true;
} else {
// Process validations.
valid = super.processValidate(request, response, form,
mapping);
}
} else {
// Process validations.
valid = super.processValidate(request, response, form,
mapping);
}
log.exiting(CLASS_NAME, METHOD_NAME);
return valid;
}