struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Al Sutton" ...@al-and-andrea.org.uk>
Subject RE: [S2] ActionMessages and redirects
Date Mon, 04 Jun 2007 05:59:17 GMT
Hi Gunnar,

I've been through the same thing, so I can help you out :).

If your actions extend com.opensymphony.xwork2.ActionSupport you can then
call the method;

addActionMessage("string")

Or

addActionError("string");

Please note, "string" is the literal message, not a key into a properties
file.

If you want to use a properties file for multi-language systems you need to
do the following;

addActionMessage(getText("key"))

Or

addActionError(getText("key"))

And create a file called package.properties in your action package (or at
some point above in the package hierarchy) which has the translations.

You will need to use the message store interceptor where you are using a
redirect (i.e. you will need it in the redirect to the get), you should note
though, at the moment there appears to be a bug in that if you use
addActionError, the message store interceptor, and you have the validation
interceptor enabled you will get redirected to the input result of the
action after the redirect :(.

Hope this helps,

Al.

-----Original Message-----
From: Gunnar Hillert [mailto:gunnar@hillert.com] 
Sent: 04 June 2007 05:52
To: user@struts.apache.org
Subject: [S2] ActionMessages and redirects


Hi,

Still learning but I am really going to like Struts 2. An area where I find
it a bit lacking though (Compared to Struts 1) is the support for action
messages to survive redirects. 

I really like to follow the 'Post/Redirect/Get pattern' for most of my
actions. 
(See also http://www.theserverside.com/patterns/thread.tss?thread_id=20936)

Therefore in most of my actions I have the requirement that my success
messages survive the next redirect.

In Struts 1 I can do:

messages.add(ActionMessages.GLOBAL_MESSAGE, 
                       new ActionMessage("user.added"));
saveMessages(request.getSession(), messages);

But there is nothing like this in Struts 2.

I did not find too much information about this requirement in Struts 2. 
There are 2 open issues in Jira that touch the issue:

https://issues.apache.org/struts/browse/WW-1623
https://issues.apache.org/struts/browse/WW-1572

On of the issues mentions the MessageStore interceptor but that looks a bit
like overkill to me. (See also
http://cwiki.apache.org/WW/message-store-interceptor.html)

Thus, for right now I am using Appfuse's solution of using a custom filter. 
(See
https://appfuse-light.dev.java.net/source/browse/appfuse-light/trunk/src/mai
n/java/org/appfuse/web/MessageFilter.java)

This works great but somehow feels like a 'hack' (Had to do the same for my
Spring MVC projects.)

* * *

In a perfect world I would like to see a feature similar to Ruby on Rails'
Flash which allows you to not only store messages but any object in a Flash,
and hence those objects survive the next redirect.

See also http://api.rubyonrails.com/classes/ActionController/Flash.html

But for the time being I would be already quite happy if there was a simple
and standardized way to have my actionMessages survive redirects.

What is the status on that? Is this something that will be added to one of
the next Struts 2 releases?

Thanks a lot! 

Regards,

Gunnar Hillert 

--
View this message in context:
http://www.nabble.com/-S2--ActionMessages-and-redirects-tf3863054.html#a1094
3759
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
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


Mime
View raw message