You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Kakunje, Chidananda (B.)" <ck...@ford.com> on 2003/11/11 20:13:28 UTC

RE: Suggestion: way to execute code after form.validate(mapping, request) fails, but before forward to input

ActionErrors is a collection. So once the processValidate() is called, you can check any errors present in the collection and take action accordingly, before forwarding in your Action class.

--Chida

-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@alaska.net]
Sent: Tuesday, November 11, 2003 1:02 PM
To: struts-dev@jakarta.apache.org
Subject: Suggestion: way to execute code after form.validate(mapping,
request) fails, but before forward to input


I'm using Struts 1.1.

I want to execute code only if validation fails, but before the forward to 
the input action.
Unfortunately, it seems that RequestProcessor.processValidate() has 
tightly-coupled these two activities, leaving no way for such activity to be 
triggered.

At first, I thought I could subclass RequestProcessor and set a boolean 
variable before calling processValidate() and check it on doForward(), 
executing my code if the variable was set, but this will probably fail in a 
multithreaded environment.  Even if I could make this work by temporarily 
setting attributes on my request, it'd still be an ugly hack.

I don't see any reasonable solution to my problem other than subclassing 
RequestProcessor, copying processValidate() into it, and making my change 
there, which seems likely to break after a struts upgrade.

I'd like to recommend that in some future struts version that 
RequestProcessor.processValidate() provide a hook for executing code between 
failed validation and forwarding to the input mapping.

In fact, it seems to me that this whole section of code

======================
        // Has an input form been specified for this mapping?
        String input = mapping.getInput();
        if (input == null) {
            if (log.isTraceEnabled()) {
                log.trace("  Validation failed but no input form 
available");
            }
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                               getInternal().getMessage("noInput",
                                                        mapping.getPath()));
            return (false);
        }

        // Save our error messages and return to the input form if possible
        if (log.isDebugEnabled()) {
            log.debug(" Validation failed, returning to '" + input + "'");
        }
        request.setAttribute(Globals.ERROR_KEY, errors);

        if (moduleConfig.getControllerConfig().getInputForward()) {
            ForwardConfig forward = mapping.findForward(input);
            processForwardConfig( request, response, forward);
        } else {
            internalModuleRelativeForward(input, request, response);
        }
======================

should be moved to the equivalent of a 
RequestProcessor.processValidateFailure() method which could then be 
subclassed.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org