Take the 2-minute tour ×

I want to create a custom template engine like velocity or freemarker which will be used in struts 2 based application. Why I don't want to use any of the available template engines is because, I want to keep the HMTL fixed and editable by dreamweaver means no struts tags or JSTL. The values will be injected with Xpath or simple string replacement of values of existing HTML tags. I require:

plain HTML + some configuration (properties/xml) + data =>

HTML populated with data + some dynamically generated javascripts

share|improve this question
What is your question? –  Steven Benitez Dec 7 '10 at 13:34
How do I write a template engine like freemarker? How to integrate my template engine with struts2? –  samarjit samanta Dec 8 '10 at 1:17
add comment

1 Answer

up vote 2 down vote accepted

1) Define a package with the name of your result type and the class that will be called when an action returns that result type.

    <result-type name="myResultType" class="com.awesome.MyResult"/> 
  .... actions and other things...

2) Implement the Struts 2 result type class:

package com.awesome;
public class MyResult extends StrutsResultSupport{
  //1) read the the target file
  //2) process/transform the target file
  //3) write out the transformed file as the result

There is a good description of this in "Apache Struts 2 web application Development" by Dave Newton. I know the above class isn't implemented but I bet you can find what you need from here.

share|improve this answer
Thanks, I am using that now. For other, who wish to use this I can give you some pointers. Open up struts default look for interceptors implementing class FreemarkerResult.java and XSLTResult.java are two classes I read through and its fairly simple as to what they do. I would also recomment going through http://www.oracle.com/technetwork/java/filters-137243.html about java Filters especially if you want to modify the response. HttpResponseWrapper is required. One more thing exists PreResultListener, which can manipulate invocation object just before result is going to be evaluated. –  samarjit samanta Dec 21 '10 at 8:16
add comment

Your Answer


