aspose file tools*
The moose likes Groovy and the fly likes Can I access messages.properties from a groovy class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Can I access messages.properties from a groovy class?" Watch "Can I access messages.properties from a groovy class?" New topic
Author

Can I access messages.properties from a groovy class?

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Hi All,
I am having a hard time finding documentation on something, which is making me think it is possibly something I shouldn't be trying to do. I know how to access the values in messages.properties from a gsp file using the tag <g:message, however, I have a couple of groovy files that I need to load a configurable string file in, and I wanted to put that string into messages.properties, however, I cannot seem to find a way to access the messages.properties files from the groovy class. The only thing I have found is how to do this in a controller,

>

But what I need is to load a string that is not an error message, it is something I am going to put into a list that will provide for a drop down list.

If anyone knows of a good resource they could point me to, I would appreciate it.
Thanks!
Kim
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

The message bundles are just sitting in the classpath. You should be able to just look them up via the standard Java Resource Bundle methods. That said, I'm curious as to why you want to store these in the messages.properties file since they clearly aren't messages. Are they even localizable Strings? If not, I'd put them in the database or Config.groovy.


GenRocket - Experts at Building Test Data
Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 274
Thank you Gregg,
I had some groovy code that was determining the contents of a list which would then be used on the page as a drop down list. I know this sounds strange, but I was getting all the values from a database, but have to replace one of the values with a different string. Something like

List = apple, pear, peach

and I want the drop down to read

List = apple, pear, banana

So, I wanted to store the string "banana" in the messages.properties file.

I have decided to put it into a different properties file, thanks for your input.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I access messages.properties from a groovy class?