File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes Can I access from a groovy class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Can I access from a groovy class?" Watch "Can I access from a groovy class?" New topic

Can I access from a groovy class?

Kim Kantola
Ranch Hand

Joined: May 17, 2001
Posts: 276
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 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, however, I cannot seem to find a way to access the 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.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

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 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: 276
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 file.

I have decided to put it into a different properties file, thanks for your input.
I agree. Here's the link:
subject: Can I access from a groovy class?
It's not a secret anymore!