|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.extras.service.FreemarkerTemplateService
public class FreemarkerTemplateService
Provides a Freemarker TemplateService class.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <click-app charset="UTF-8"> <pages package="org.apache.click.examples.page"/> <template-service classname="org.apache.click.extras.service.FreemarkerTemplateService"/> </click-app>Please note that Click ships with a default error.htm that is tailored for Velocity. If you switch to Freemarker replace the default error.htm with the one shown below. To ensure Click uses your template instead of the default one, copy/paste the template below to the web application path /click/error.htm. Click won't override your custom template.
<html> <head> <title>Error Page</title> <style type='text/css'> body, table, td { font-family: arial, sans-serif; font-size: 12px; } td.header { color: white; background: navy; } .errorReport { display: none; } a { color: blue; } </style> <script type='text/javascript'> function displayError() { errorReport.style.display = 'block'; } </script> </head> <body> <h1>Error Page</h1> <#if errorReport??> The application encountered an unexpected error. <p/> To return to the application click <a href="${context}">here</a>. <p/> <#if mode != "production"> To view the error details click <a href="#" onclick="displayError();">here</a>. <p/> ${errorReport} <p/> </#if> </#if> </body> </html>
Field Summary | |
---|---|
protected int |
cacheDuration
The production/profile mode cache duration in seconds. |
protected ConfigService |
configService
The application configuration service. |
protected freemarker.template.Configuration |
configuration
The Freemarker engine configuration. |
protected boolean |
deployedErrorTemplate
The /click/error.htm page template has been deployed. |
protected boolean |
deployedNotFoundTemplate
The /click/not-found.htm page template has been deployed. |
protected static String |
ERROR_PAGE_PATH
The click error page template path. |
protected static String |
NOT_FOUND_PAGE_PATH
The click not found page template path. |
Constructor Summary | |
---|---|
FreemarkerTemplateService()
|
Method Summary | |
---|---|
int |
getCacheDuration()
Return the template cache duration in seconds to use when the application is in "production" or "profile" mode. |
void |
onDestroy()
|
void |
onInit(ServletContext servletContext)
|
void |
renderTemplate(Page page,
Map<String,?> model,
Writer writer)
|
void |
renderTemplate(String templatePath,
Map<String,?> model,
Writer writer)
|
void |
setCacheDuration(int cacheDuration)
Return the template cache duration in seconds to use when the application is in "production" or "profile" mode. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final String ERROR_PAGE_PATH
protected static final String NOT_FOUND_PAGE_PATH
protected freemarker.template.Configuration configuration
protected int cacheDuration
protected ConfigService configService
protected boolean deployedErrorTemplate
protected boolean deployedNotFoundTemplate
Constructor Detail |
---|
public FreemarkerTemplateService()
Method Detail |
---|
public void onInit(ServletContext servletContext) throws Exception
onInit
in interface TemplateService
servletContext
- the application servlet context
Exception
- if an error occurs initializing the Template ServiceTemplateService.onInit(javax.servlet.ServletContext)
public void onDestroy()
onDestroy
in interface TemplateService
TemplateService.onDestroy()
public void renderTemplate(Page page, Map<String,?> model, Writer writer) throws IOException, TemplateException
renderTemplate
in interface TemplateService
page
- the page template to rendermodel
- the model to merge with the template and renderwriter
- the writer to send the merged template and model data to
IOException
- if an IO error occurs
TemplateException
- if template error occursTemplateService.renderTemplate(Page, Map, Writer)
public void renderTemplate(String templatePath, Map<String,?> model, Writer writer) throws IOException, TemplateException
renderTemplate
in interface TemplateService
templatePath
- the path of the template to rendermodel
- the model to merge with the template and renderwriter
- the writer to send the merged template and model data to
IOException
- if an IO error occurs
TemplateException
- if template error occursTemplateService.renderTemplate(String, Map, Writer)
public int getCacheDuration()
public void setCacheDuration(int cacheDuration)
cacheDuration
- the template cache duration in seconds to set
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |