Loading from MessageResources.properties in Struts 2
Dave Alvarado
Ranch Hand
Joined: Jul 02, 2008
Posts: 434
posted
0
Hi,
I'm migrating my Struts 1 application to Struts 2. In my Struts 1 app, I had a MessageResources.properties file in which I stored key-value pairs of error messages. For example,
error.no.redirect.found=No redirect could be found because the database is down.
How can I continue to utilize these properties in Struts 2? In my action class, I have this validate method ...
But right now, the string "actionError" is a key in the properties file. How do I turn it in to the value? Thanks, - Dave
Thanks. A follow up to this, what does the properties file need to be called? Currently, I have a MessageResources.properties file in my classpath, but obviously I need to tell struts.xml about the file somehow or rename it to what it is expecting.
XML configuration is preferred over the properties file.
Dave Alvarado
Ranch Hand
Joined: Jul 02, 2008
Posts: 434
posted
0
I added a file "MyAction.properties" in the same directory as the class for that file and everything loaded correctly.
Thanks, - Dave
Shashank Rudra
Ranch Hand
Joined: Mar 26, 2009
Posts: 131
posted
0
I think the XML way of configuration in not present in Struts2.0.6 version. As when I am trying to declate the property file in struts.xml as I am getting this error Or can it be worked out in 2.0.6 also someway?
Note the struts.custom.i18n.resources property, although XML property configuration is preferred. See this also (FAQ entry).
Shashank Rudra
Ranch Hand
Joined: Mar 26, 2009
Posts: 131
posted
0
ok. So David when you say XML way of doing it - you mean Listener way of doing it. However will creating an additional class- be not overhead, if the messages are being picked from the struts.properties file using
I have no idea what you're talking about. There are no listeners or additional classes: just set the constant in the XML config file (or web.xml) instead of in a struts.properties file--just like it says in the XML config link I provided.
Shashank Rudra
Ranch Hand
Joined: Mar 26, 2009
Posts: 131
posted
0
oh I was following the link attached to
see this also
this ahead of the one I was to see. My mistake. Though what that Listener in there is for? Thanks David for all the help.