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

2003-11-11 Thread Mike Kienenberger
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-11-11 Thread David Graham

--- Mike Kienenberger [EMAIL PROTECTED] wrote:
 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.

Sounds like a good candidate for a command in the future Struts Chain
reimplementation of the RequestProcessor.

David

 
 -Mike
 
 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 


__
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-11-11 Thread Kakunje, Chidananda (B.)
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:[EMAIL PROTECTED]
Sent: Tuesday, November 11, 2003 1:02 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-11-11 Thread Carlos Fernandez
you can go thru the list of errors by name, by iterating on
ActionErrors.properties property.

-Carlos.

-Original Message-
From: Kakunje, Chidananda (B.) [mailto:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
Sent: Tuesday, November 11, 2003 1:02 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



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

2003-11-11 Thread Mike Kienenberger
Gupta, Sahil [EMAIL PROTECTED] wrote:
 I think that Mike is talking about the case where he uses the validation 
fwk. 
 There is no way, what he is asking for can be done with the current
 implementation(but for implementing the processValidate in your own RP) of
 the RP but i think that this should be a nice addition to the future
 implementation.

Right.

Since processValidate calls doForward([input]), it's too late to check 
ActionErrors after calling processValidate.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]