0

I have a special action that loads pages that extends the ActionSupport class. This allows me to access properties file values using the getText() method. My action requires a list of files to be loaded for any page.

I know that this is possible using the Configuration object: Loading a list of values from a properties file

public class MainAction extends ActionSupport{
..
..
    public String loadHomepage() throws Exception {
        page.setPageTitle(getText("homePage.title"));
        page.setCssFiles(getText("homePage.cssFiles"));
        page.setJsFiles(getText("homePage.jsFiles"));
        return INPUT;
    }
..
..
}

MainAction.properties

homePage.title=Home Page
homePage.cssFiles=a.css,b.css,c.css
homePage.jsFiles=a.js,b.js,c.js

I know that an obvious way would be to get the list and then split it manually by using comma as the delimiter. But is there any faster/cleaner way in struts2 to obtain these list of properties?

Colenso Castellino
  • 900
  • 2
  • 13
  • 23
  • 1
    Personally, I'd aim to put this stuff in the templating mechanism, not in actions. This puts non-data view mechanics in an awkward place, and I'd be a little skeptical you need this level of granularity. Even if you *did*, I'd likely aim for something more convention-oriented to avoid so much overhead: ugh. – Dave Newton Nov 20 '12 at 03:45
  • Can you please elaborate? What is this "templating mechanism" that you have mentioned? What could be an optimal way of doing this? – Colenso Castellino Nov 21 '12 at 04:31
  • *Any* templating mechanism. I'm saying this kind of stuff, if required at all, imo doesn't belong in the action, and I'd be a little surprised if it needed to be handled manually at all. – Dave Newton Nov 21 '12 at 11:31

0 Answers0