aspose file tools*
The moose likes Struts and the fly likes Are Struts 2 properties available in freemarker templates? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Are Struts 2 properties available in freemarker templates?" Watch "Are Struts 2 properties available in freemarker templates?" New topic
Author

Are Struts 2 properties available in freemarker templates?

Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
Hi,
I wonder if anyone can help.
I'm putting together a S2 application and have used "struts.custom.properties" in struts.properties to point to a properties file with my own application specific properties within it. Essentially the properties that I am providing are a series of application defaults.


Within a component class I can reference these properties with DI like this:


This works great and I can then reference layoutCol1 within my component class. However, I need access to these properties within my ftl templates, and ideally I want to do away with using DI to access them in my class.
What I'd like to do in my ftl is something like:


But I just cant get it. Either I've got the syntax wrong; or I've misunderstood the concept of properties (in properties files) vs. paramaters vs. OGNL vs. stacks



If anyone could point me in the right direction I'd very much appreciate it;
Cheers

Nathan
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use the s:text tag, if you're just getting labels.
Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
Thank you for your reply. My values in my properties file are more used to control logic of the application, rather than labels as such (even though I've used the phrase 'label' in my example). What I need to do in my ftl template is perform some logic based on the values of the properties, hence me wanting to do something like

What I'm trying to achieve is that I have a properties file that contains defaults for how the web app is laid out - ie. the default for column 1 is the field label; but these defaults can be overridden by using extra attributes that I've added to the tld for each field type so that for a given field you can say that column 1 has the field itself and column 2 has the label

Does this explain better what I'm trying to do?

Cheers

Nathan
Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
Ive just though about my last post and thought might be serving to confuse!, so here is (hopefully) a better example.
I want to do something like this in my ftp template:


where layoutCol1FromTagAttributes and layoutCol1FromTagAttributes are optional attributes on the tag and if provided on the tag are added as parameters in the component class; and defaultLayoutCol1FromPropsFile and defaultLayoutCol2FromPropsFile are properties in my custom properties file.

So, back to the original question, how do I reference defaultLayoutCol1FromPropsFile and defaultLayoutCol2FromPropsFile in the ftl file in the way I am trying to?

Cheers
Nathan
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

As far as I know you've have to expose them as action properties. You don't need DI for that, just use one of ActionSupport's getText methods.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Are Struts 2 properties available in freemarker templates?