It appears that extending LookupDispatchAction does *not* cause
validation to be bypassed when the following tag is used in a JSP:

<html:cancel property="method">
    <bean:message key="common.button.cancel" />
</html:cancel>


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";
 

    /**
     * <p> 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.</p>
     *
     * @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;
    }

****************************************
*  Cell Phone: 248.866.4897 (free incoming calls)
****************************************

Reply via email to