You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Greg Akins <an...@gmail.com> on 2010/11/19 17:17:55 UTC

Problem with Validation "lifecycle"

I've written an action, with validation, that uses a redirectAction
instead of a .jsp for the INPUT result.

When the final INPUT jsp is displayed, the actionErrors aren't
present.  I believe this is because the action I'm redirecting to
"clears" the actions before the jsp is displayed.  If I save an
actionError on the session, I can retrieve it in the final error...
but this seems less than ideal, and I'm not sure how to get to the
annotation based validators ( I added a session.put() in the
validate() method.

Is there a way to "carry" the errors across actions in this case? The
INPUT needs to redirect to an action because the action determines
whether certain fields need displayed.. if the INPUT goes straight to
a jsp, the jsp is blank because of the logic I'm using to display
fields.

Struts 2.2.1

-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Problem with Validation "lifecycle"

Posted by Greg Akins <an...@gmail.com>.
On Fri, Nov 19, 2010 at 11:43 AM, Greg Lindholm <gr...@gmail.com> wrote:
> I wrote this to solve the problem of preserving messages across a redirect:
>
> http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/
>

Thanks Greg.  That looks like exactly what I was looking for.  One
question to you, or to the list, someone that commented on your blog
mentioned the MessageStoreInterceptor.  Any pros or cons of using that
over your interceptor?

-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Problem with Validation "lifecycle"

Posted by Greg Lindholm <gr...@gmail.com>.
I wrote this to solve the problem of preserving messages across a redirect:

http://glindholm.wordpress.com/2008/07/02/preserving-messages-across-a-redirect-in-struts-2/


On Fri, Nov 19, 2010 at 11:36 AM, Greg Akins <an...@gmail.com> wrote:
> Thanks for the response
>
> On Fri, Nov 19, 2010 at 11:28 AM, Maurizio Cucchiara
> <ma...@gmail.com> wrote:
>> As far I can remember actionError are stored in struts stack, so I guess
>> they are per-request.
>
> That's what I thought.
>
>> Also, redirect action create a new request, so you can share AE in a
>> standard flow.
>
> I CAN share actionErrors in the standard flow, but if I use
> redirectAction I lose the original request, right?
>
>> Can't you do without redirect for the input result?
>
> The problems is that when I create the jsp, I set values for whether
> the fields are to be displayed.  Since those are set in the action, if
> I skip that action the fields are displayed.
>
> The only other thing I can think of is to set the display in the other
> action (the one that is redirecting from).. but since I'm falling out
> of the interceptor stack and not getting into the execute method on
> the action, I'm not sure of how I'd do that either.
>
>> 2010/11/19 Greg Akins <an...@gmail.com>
>>>
>>> I've written an action, with validation, that uses a redirectAction
>>> instead of a .jsp for the INPUT result.
>>>
>>> When the final INPUT jsp is displayed, the actionErrors aren't
>>> present.  I believe this is because the action I'm redirecting to
>>> "clears" the actions before the jsp is displayed.  If I save an
>>> actionError on the session, I can retrieve it in the final error...
>>> but this seems less than ideal, and I'm not sure how to get to the
>>> annotation based validators ( I added a session.put() in the
>>> validate() method.
>>>
>>> Is there a way to "carry" the errors across actions in this case? The
>>> INPUT needs to redirect to an action because the action determines
>>> whether certain fields need displayed.. if the INPUT goes straight to
>>> a jsp, the jsp is blank because of the logic I'm using to display
>>> fields.
>>>
>>> Struts 2.2.1
>>>
>>> --
>>> Greg Akins
>>>
>>> http://insomnia-consulting.org
>>> http://www.pghcodingdojo.org
>>> http://pittjug.dev.java.net
>>> http://twitter.com/akinsgre
>>> http://www.linkedin.com/in/akinsgre
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>>
>>
>> --
>> Maurizio Cucchiara
>>
>
>
>
> --
> Greg Akins
>
> http://insomnia-consulting.org
> http://www.pghcodingdojo.org
> http://pittjug.dev.java.net
> http://twitter.com/akinsgre
> http://www.linkedin.com/in/akinsgre
>
> ---------------------------------------------------------------------
> 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


Re: Problem with Validation "lifecycle"

Posted by Greg Akins <an...@gmail.com>.
Thanks for the response

On Fri, Nov 19, 2010 at 11:28 AM, Maurizio Cucchiara
<ma...@gmail.com> wrote:
> As far I can remember actionError are stored in struts stack, so I guess
> they are per-request.

That's what I thought.

> Also, redirect action create a new request, so you can share AE in a
> standard flow.

I CAN share actionErrors in the standard flow, but if I use
redirectAction I lose the original request, right?

> Can't you do without redirect for the input result?

The problems is that when I create the jsp, I set values for whether
the fields are to be displayed.  Since those are set in the action, if
I skip that action the fields are displayed.

The only other thing I can think of is to set the display in the other
action (the one that is redirecting from).. but since I'm falling out
of the interceptor stack and not getting into the execute method on
the action, I'm not sure of how I'd do that either.

> 2010/11/19 Greg Akins <an...@gmail.com>
>>
>> I've written an action, with validation, that uses a redirectAction
>> instead of a .jsp for the INPUT result.
>>
>> When the final INPUT jsp is displayed, the actionErrors aren't
>> present.  I believe this is because the action I'm redirecting to
>> "clears" the actions before the jsp is displayed.  If I save an
>> actionError on the session, I can retrieve it in the final error...
>> but this seems less than ideal, and I'm not sure how to get to the
>> annotation based validators ( I added a session.put() in the
>> validate() method.
>>
>> Is there a way to "carry" the errors across actions in this case? The
>> INPUT needs to redirect to an action because the action determines
>> whether certain fields need displayed.. if the INPUT goes straight to
>> a jsp, the jsp is blank because of the logic I'm using to display
>> fields.
>>
>> Struts 2.2.1
>>
>> --
>> Greg Akins
>>
>> http://insomnia-consulting.org
>> http://www.pghcodingdojo.org
>> http://pittjug.dev.java.net
>> http://twitter.com/akinsgre
>> http://www.linkedin.com/in/akinsgre
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
>
> --
> Maurizio Cucchiara
>



-- 
Greg Akins

http://insomnia-consulting.org
http://www.pghcodingdojo.org
http://pittjug.dev.java.net
http://twitter.com/akinsgre
http://www.linkedin.com/in/akinsgre

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


Re: Problem with Validation "lifecycle"

Posted by Maurizio Cucchiara <ma...@gmail.com>.
As far I can remember actionError are stored in struts stack, so I guess
they are per-request.
Also, redirect action create a new request, so you can share AE in a
standard flow.
Can't you do without redirect for the input result?

2010/11/19 Greg Akins <an...@gmail.com>

> I've written an action, with validation, that uses a redirectAction
> instead of a .jsp for the INPUT result.
>
> When the final INPUT jsp is displayed, the actionErrors aren't
> present.  I believe this is because the action I'm redirecting to
> "clears" the actions before the jsp is displayed.  If I save an
> actionError on the session, I can retrieve it in the final error...
> but this seems less than ideal, and I'm not sure how to get to the
> annotation based validators ( I added a session.put() in the
> validate() method.
>
> Is there a way to "carry" the errors across actions in this case? The
> INPUT needs to redirect to an action because the action determines
> whether certain fields need displayed.. if the INPUT goes straight to
> a jsp, the jsp is blank because of the logic I'm using to display
> fields.
>
> Struts 2.2.1
>
> --
> Greg Akins
>
> http://insomnia-consulting.org
> http://www.pghcodingdojo.org
> http://pittjug.dev.java.net
> http://twitter.com/akinsgre
> http://www.linkedin.com/in/akinsgre
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Maurizio Cucchiara