Source

webwork / docs / wwfreemarker.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US" xml:lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <title>OpenSymphony Wiki (Offline Version) :: WebWork2 Documentation</title>
  <link type="text/css" href="main.css" rel="STYLESHEET"/>
</head>
<body>
  <div id="page-logo">
    <a href="index.html">WebWork2 Documentation</a>
  </div>
    <div class="snip-title">
	  <h1 class="snip-name">WebWorkFreemarkerSupport
  
  </h1>
  </div>
<div id="snip-content" class="snip-content">

 <div class="snip-attachments"></div>
 
 these docs are a realllly quick hack together to get something up on the wiki.<p class="paragraph"/>I will try and polish them up over the next few days / weeks as time permits.<p class="paragraph"/>Please message the webwork mailing list for assistance.
<h3 class="heading-1">Configuring web.xml
</h3><p class="paragraph"/>To use freemarker as a view engine, the webwork2 FreemarkerServlet needs to be configured, and mapped to the file extension that you use for your templates.<p class="paragraph"/><div class="code"><pre>&#60;servlet&#62;
  &#60;servlet&#45;name&#62;freemarker&#60;/servlet&#45;name&#62;
  &#60;servlet&#45;class&#62;com.opensymphony.webwork.views.freemarker.FreemarkerServlet&#60;/servlet&#45;class&#62;
&#60;/servlet&#62;<p class="paragraph"/>&#60;servlet&#45;mapping&#62;
  &#60;servlet&#45;name&#62;freemarker&#60;/servlet&#45;name&#62;
  &#60;url&#45;pattern&#62;&#42;.ftl&#60;/url&#45;pattern&#62;
&#60;/servlet&#45;mapping&#62;</pre></div>
<h3 class="heading-1-1">xwork.xml configuration
</h3><p class="paragraph"/>To use the freemarker view, just use the DISPATCHER result type, and specify the location to the template file.<p class="paragraph"/><div class="code"><pre>&#60;action name=<span class="java&#45;quote">"test"</span> class=<span class="java&#45;quote">"<span class="java&#45;keyword">package</span>.Test"</span>&#62;
  &#60;result name=<span class="java&#45;quote">"success"</span> type=<span class="java&#45;quote">"dispatcher"</span>&#62;/WEB&#45;INF/views/testView.ftl&#60;/result&#62;
&#60;/action&#62;</pre></div>
<h3 class="heading-1-1">objects in the context
</h3>
<ul class="star">
<li>statck - the value stack for manually looking up expressions using stack.findValue(String).</li>
</ul><p class="paragraph"/>NOTE : your action properties are automatically resolved just like in a velocity view. so ${name} will result in stack.findValue("name"), which results in action.getName() being executed.
<ul class="star">
<li>wwUtil - an instance of the com.opensymphony.webwork.views.freemarker.FreemarkerUtil class.</li>
</ul><p class="paragraph"/>This class contains useful methods to execute OGNL expressions against arbitary objects, and a method to generate a select list using the &#60;ww:select&#62; pattern. (i.e. taking the name of the list property, a listKey and listValue)
<h3 class="heading-1-1">extending the servlet
</h3><p class="paragraph"/>Please refer to the freemarker site for details about the base freemarker servlet.<p class="paragraph"/>Be carfeul when subclassing com.opensymphony.webwork.views.freemarker.FreemarkerServlet when overriding<p class="paragraph"/><div class="code"><pre><span class="java&#45;keyword">protected</span> TemplateModel createModel(<p class="paragraph"/>    ObjectWrapper wrapper,<p class="paragraph"/>    ServletContext servletContext,<p class="paragraph"/>    HttpServletRequest request,<p class="paragraph"/>    HttpServletResponse response)</pre></div><p class="paragraph"/>Please call super.createModel(...) and wrap it with a new model to avoid problems with action property resoloution.
<h3 class="heading-1-1">using webwork UI tags
</h3><p class="paragraph"/>Freemarker has builtin support for using JSP taglibs.<p class="paragraph"/><div class="code"><pre>&#60;#assign ww=JspTaglibs&#91;<span class="java&#45;quote">"/WEB&#45;INF/webwork.tld"</span>&#93; /&#62;<p class="paragraph"/>&#60;@ww.form method=<span class="java&#45;quote">"post"</span> name=<span class="java&#45;quote">"inputform"</span> action=<span class="java&#45;quote">"save.action"</span> &#62;<p class="paragraph"/>    &#60;@ww.hidden name=<span class="java&#45;quote">"id"</span> /&#62;<p class="paragraph"/>    &#60;@ww.textarea label=<span class="java&#45;quote">"Details"</span> name=<span class="java&#45;quote">"details"</span> rows=5 cols=40 /&#62;<p class="paragraph"/>    &#60;@ww.submit value=<span class="java&#45;quote">"'Save'"</span> align=<span class="java&#45;quote">"center"</span> /&#62;<p class="paragraph"/>&#60;/@ww.form&#62;</pre></div><p class="paragraph"/>NOTE : numeric properties for tags MUST be numbers, not strings.  as in the rows and cols properties above.  if  you use cols="40" you will receive an exception.  Other than that, the freemarker tag container behaves as you would expect.<p class="paragraph"/>
  </div>
</body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.