[S2] Proper way to clear error messages in session scope

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[S2] Proper way to clear error messages in session scope

Diego Manilla Suárez
Hi. I have an action in session scope. The problem is that action errors
are never cleared and thus are shown repeatedly whenever the user sends
the form with validation errors.

At first I put a call to clearErrors() at the beginning of mi validate()
method, but now I'm using also the validation framework, so if I do
that, I'm clearing its validation errors too before they are even shown.

I think the right place to clear errors would be right after they are
printed, but I don't see any tag to do that.

Thanks in advance.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [S2] Proper way to clear error messages in session scope

Laurie Harper
Diego Manilla Suárez wrote:

> Hi. I have an action in session scope. The problem is that action errors
> are never cleared and thus are shown repeatedly whenever the user sends
> the form with validation errors.
>
> At first I put a call to clearErrors() at the beginning of mi validate()
> method, but now I'm using also the validation framework, so if I do
> that, I'm clearing its validation errors too before they are even shown.
>
> I think the right place to clear errors would be right after they are
> printed, but I don't see any tag to do that.
>
> Thanks in advance.

Struts 2 actions are intended to be request scoped, not session scoped.
You should re-work your action to store data you wish to persist across
requests in the session, rather than storing the action itself in the
session.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [S2] Proper way to clear error messages in session scope

Diego Manilla Suárez
In reply to this post by Diego Manilla Suárez
Well, I've put this line just below the tags <s:actionerror /> and
<s:fielderror />:

<%((ActionSupport)
ActionContext.getContext().getActionInvocation().getAction()).clearErrorsAndMessages();%>

I don't like putting Java code on JSPs and I'm sure there is a better
way to do it, but so far it's working.

Regards,
Diego.

Diego Manilla Suárez escribió:

> Hi. I have an action in session scope. The problem is that action
> errors are never cleared and thus are shown repeatedly whenever the
> user sends the form with validation errors.
>
> At first I put a call to clearErrors() at the beginning of mi
> validate() method, but now I'm using also the validation framework, so
> if I do that, I'm clearing its validation errors too before they are
> even shown.
>
> I think the right place to clear errors would be right after they are
> printed, but I don't see any tag to do that.
>
> Thanks in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [S2] Proper way to clear error messages in session scope

Charles Wiese
Are we the only ones that felt using Session-scoped Actions was the best way to keep "model" information between requests for "wizard-like" or multi-page flows?   Even ModelDriven interface didn't help ....since the Action is normally request scope.   Does the sound of manually adding every Action property (or Moddel) to the session yourself seem like hacking the framework?   I seen some sites decribing "conversational-scope" interceptor - maybe this would be the "proper" approach.

Diego Manilla Suárez wrote
Well, I've put this line just below the tags <s:actionerror /> and
<s:fielderror />:

<%((ActionSupport)
ActionContext.getContext().getActionInvocation().getAction()).clearErrorsAndMessages();%>

I don't like putting Java code on JSPs and I'm sure there is a better
way to do it, but so far it's working.

Regards,
Diego.

Diego Manilla Suárez escribió:
> Hi. I have an action in session scope. The problem is that action
> errors are never cleared and thus are shown repeatedly whenever the
> user sends the form with validation errors.
>
> At first I put a call to clearErrors() at the beginning of mi
> validate() method, but now I'm using also the validation framework, so
> if I do that, I'm clearing its validation errors too before they are
> even shown.
>
> I think the right place to clear errors would be right after they are
> printed, but I don't see any tag to do that.
>
> Thanks in advance.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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