wood burning stoves 2.0*
The moose likes Struts and the fly likes Configuring FreeMarker(.ftl) with Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Configuring FreeMarker(.ftl) with Struts 2" Watch "Configuring FreeMarker(.ftl) with Struts 2" New topic
Author

Configuring FreeMarker(.ftl) with Struts 2

Kumar Sonu
Ranch Hand

Joined: Apr 05, 2011
Posts: 36
I am trying to configure FreeMarker(.ftl) with an application which is using Struts 2 (for views and actions) and Spring (for dependency injections).
I want to keep the template files (.ftl) in the application root folder. I am however not able to achieve.

The FreeMarker documention says that to make the template available to the application we need to place the template in either of these locations:
1. Classpath
2. Application root

With classpath it works fine for me but my requirement is different. Now to achieve this is tried to configure FreeMarker for struts/spring by telling the container the path where the template files are present. The following are the approaches:

STRUTS web.xml file


In SPRING's application-context.xml


However, both the approaches are not working. Am I missing something here ? Please help me out.


SCJP,SCWCD, SCDJWS
Mars Mondal
Greenhorn

Joined: Jan 01, 2011
Posts: 14
I am not sure I understood the problem you are having. If you are using freemarker for a custom struts 2 template.Have you set your struts.properties to specify that you are using the custom theme?The struts.properties will be something like this :
Kumar Sonu
Ranch Hand

Joined: Apr 05, 2011
Posts: 36
That is true. I am using custom struts2 template but I have not set the properties. I will try setting the properties and try.
Kumar Sonu
Ranch Hand

Joined: Apr 05, 2011
Posts: 36
Mars,
On another note could you also please suggest which of the approaches out of the ones I had mentioned (Struts/Spring) should be used ?
Kumar Sonu
Ranch Hand

Joined: Apr 05, 2011
Posts: 36
Mars,
I tried setting the property, but I am facing the same problem.
The application does not pick up my customized ftl files but picks up the default Struts ftl files.

Note: I have modified the actionerror.ftl file to display error message in red background and as plain text. The default is to show in white backgound and as list item. I want the customized ftl to work.

The following is my current configurations:




Also note, the template directoty is placed in my root folder and not inside WEB-INF.

Please help.
Mars Mondal
Greenhorn

Joined: Jan 01, 2011
Posts: 14
Hey Deepak,
Sorry for the late reply I got a little busy at work. Place your template folder inside the web-inf and see what happens. Also I see you have defined the properties in struts.xml file I think you should specify them in the struts.properties file. Try deleting those definitions from your struts.xml and then create another file called struts.properties. Copy paste what I sent you and see what happens. I will try and get you a screenshot of the folder structure to see for yourself.
Thanks,
Mars
Mars Mondal
Greenhorn

Joined: Jan 01, 2011
Posts: 14
To start the new theme you would make a template directory in your WEB-INF/classes directory, then in that one make a directory with the same name as your theme, in your case "css_xhtml". Then copy all of the files from the XHTML theme in the Struts 2 distribution intocss_xhtml to form the basis of your new theme. Again I will post you a screenshot of my computer from work tomorrow but try what I said first
Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
I was facing the same issue described above and resolved it after getting the solution as described. However I upgraded the application to Struts 2.2.3.1 and the issue described above re-occurred again.
I am using the following version of freemarker library - 2.3.16

Can someone help me.


SCJP 80% SCWCD 89%
 
Don't get me started about those stupid light bulbs.
 
subject: Configuring FreeMarker(.ftl) with Struts 2