struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Fernandez <Carlos.Fernan...@S1.com>
Subject RE: Suggestion: way to execute code after form.validate(mapping, request) fails, but before forward to input
Date Tue, 11 Nov 2003 19:15:58 GMT
you can go thru the list of errors by name, by iterating on
ActionErrors.properties property.

-Carlos.

-----Original Message-----
From: Kakunje, Chidananda (B.) [mailto:ckakunje@ford.com]
Sent: Tuesday, November 11, 2003 2:13 PM
To: 'Struts Developers List'
Subject: 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

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


Mime
View raw message