You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christian Schlaefcke <cs...@wms-network.de> on 2004/01/13 17:27:18 UTC

ActionForm - redirect to custom JSP after validation failed

Hi Folks,

I have a simple login.jsp that I want to validate. So I have a Class
"LoginForm" with a "validate" method, that fills up the ActionErrors with
the errors that might occur (missing username/password, wrong
username/password). Later the execute method of the corresponding Action
class "LoginAction" checks those ActionErrors. If not empty I try to
return a forward to "failure.jsp".

The problem I have is that before my LoginAction could execute my custom
forward the RequestProcessor of Struts tells in the logs, that validation
has failed and request will be forwarded to /login.jsp (which is of course
the input item of this action in struts-config.xml). When a validation
error occurs my LoginAction class is never called.

I searched the archive of this list already but couldn´t get through the
solutions I found there. I still don´t understand why this is happening
and what I can do to redirect to a custom failure.jsp.

Could someone please explain in newbie-style ;-) ?

Thanks & Regards!

Chris

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


Re: ActionForm - redirect to custom JSP after validation failed

Posted by Mark Lowe <ma...@talk21.com>.
You could forward (not redirect) to a generic failure page if there are 
errors present. I confess i haven;t done this but it could be what you 
want, even forward to a global forward defined in struts config, so you 
can reuse you error page for other stuff.




On 13 Jan 2004, at 16:27, Christian Schlaefcke wrote:

> Hi Folks,
>
> I have a simple login.jsp that I want to validate. So I have a Class
> "LoginForm" with a "validate" method, that fills up the ActionErrors 
> with
> the errors that might occur (missing username/password, wrong
> username/password). Later the execute method of the corresponding 
> Action
> class "LoginAction" checks those ActionErrors. If not empty I try to
> return a forward to "failure.jsp".
>
> The problem I have is that before my LoginAction could execute my 
> custom
> forward the RequestProcessor of Struts tells in the logs, that 
> validation
> has failed and request will be forwarded to /login.jsp (which is of 
> course
> the input item of this action in struts-config.xml). When a validation
> error occurs my LoginAction class is never called.
>
> I searched the archive of this list already but couldn´t get through 
> the
> solutions I found there. I still don´t understand why this is happening
> and what I can do to redirect to a custom failure.jsp.
>
> Could someone please explain in newbie-style ;-) ?
>
> Thanks & Regards!
>
> Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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


Re: ActionForm - redirect to custom JSP after validation failed

Posted by Kris Schneider <kr...@dotech.com>.
If I understand what you're asking, try setting validate="false" in your action
mapping so that validation is deferred to your action. Otherwise, Struts will
perform validation automatically and, as you've noticed, never invoke your
action if there are errors.

Another option would be to keep validate="true" (that's actually it's default
value), but change input="/failure.jsp" (or wherever else you want to forward
upon validation errors - it can even be another action).

Quoting Christian Schlaefcke <cs...@wms-network.de>:

> Hi Folks,
> 
> I have a simple login.jsp that I want to validate. So I have a Class
> "LoginForm" with a "validate" method, that fills up the ActionErrors with
> the errors that might occur (missing username/password, wrong
> username/password). Later the execute method of the corresponding Action
> class "LoginAction" checks those ActionErrors. If not empty I try to
> return a forward to "failure.jsp".
> 
> The problem I have is that before my LoginAction could execute my custom
> forward the RequestProcessor of Struts tells in the logs, that validation
> has failed and request will be forwarded to /login.jsp (which is of course
> the input item of this action in struts-config.xml). When a validation
> error occurs my LoginAction class is never called.
> 
> I searched the archive of this list already but couldn´t get through the
> solutions I found there. I still don´t understand why this is happening
> and what I can do to redirect to a custom failure.jsp.
> 
> Could someone please explain in newbie-style ;-) ?
> 
> Thanks & Regards!
> 
> Chris

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


RE: ActionForm - redirect to custom JSP after validation failed

Posted by Richard Hightower <rh...@arc-mind.com>.
First, the behavior experiencing is as designed. I suggest getting a good
book on Struts geared for Struts novices like Professional Struts published
by Wrox (written by James Goodwill and me).

You can turn validation off in the action mapping (action element in the
struts config file) by setting the validate attribute to false (the default
is true).

That said....

Here is what I would do (and have done in a similar situation).

Turn validation off by setting validate=false on the action mapping:

<action path="/foo" name="loginForm" validate="false"
type="buy.my.book.FooAction">

	<forward name="failure" ...
</action>


Have the action's execute method calll the validation method of the
ActionForm, then forward to anywhere you would like.

ActionErrors errors = form.validate();

//if errors not empty forward to failure
return mapping.findForward("failure");


Rick Hightower
Developer

Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm

Struts/J2EE consulting --
http://www.arc-mind.com/consulting.htm#StrutsMentoring

-----Original Message-----
From: Christian Schlaefcke [mailto:cschlaefcke@wms-network.de]
Sent: Tuesday, January 13, 2004 9:27 AM
To: struts-user@jakarta.apache.org
Subject: ActionForm - redirect to custom JSP after validation failed


Hi Folks,

I have a simple login.jsp that I want to validate. So I have a Class
"LoginForm" with a "validate" method, that fills up the ActionErrors with
the errors that might occur (missing username/password, wrong
username/password). Later the execute method of the corresponding Action
class "LoginAction" checks those ActionErrors. If not empty I try to
return a forward to "failure.jsp".

The problem I have is that before my LoginAction could execute my custom
forward the RequestProcessor of Struts tells in the logs, that validation
has failed and request will be forwarded to /login.jsp (which is of course
the input item of this action in struts-config.xml). When a validation
error occurs my LoginAction class is never called.

I searched the archive of this list already but couldn´t get through the
solutions I found there. I still don´t understand why this is happening
and what I can do to redirect to a custom failure.jsp.

Could someone please explain in newbie-style ;-) ?

Thanks & Regards!

Chris

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


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