Common Template Engine Release | Build >>  English | 中文
Downloads Changes Log Forums About Us
Documents
Overview
Template Reference
Expression Reference
Syntax Coat Reference
Config Guide
Expansion Guide
API Guide
FAQ
Versus Other Engine
Integration
MVC Integration
JSP Integration
Cache Integration
Logger Integration
Data Format
Javax Script Integration
Mail Sender Integration
Dependency Library
Tools
Debug Window
Viewer
Template Generator
Template Converter
Editor PlugIn
Code Case
Development
Architecture Specification
Develop Criterion
Project Planning
Requirement
Resources
Downloads
License
Changes Log
UML
Java Doc
Coverage Report
Community
Developer Team
Forums
Wiki
Mail List
Bugs List
Report Bugs Here !

 
MVC Integration Guide

1. Tools Dependency>>
(1) Servlet
web.xml:
<listener>
    <listener-class>org.commontemplate.tools.web.EngineInitializeListener</listener-class>
</listener>

<filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.commontemplate.tools.web.EncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>commontemplate</servlet-name>
    <servlet-class>org.commontemplate.tools.web.servlet.TemplateServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>commontemplate</servlet-name>
    <url-pattern>*.ctl</url-pattern>
</servlet-mapping>

(2) Struts
...

CommonTemplate in MVC:
CommonTemplate In MVC

(3) WebWork
web.xml:
<listener>
    <listener-class>org.commontemplate.tools.web.EngineInitializeListener</listener-class>
</listener>

<filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.commontemplate.tools.web.EncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

<servlet>
    <servlet-name>webwork</servlet-name>
    <servlet-class>com.opensymphony.webwork.dispatcher.ServletDispatcher</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>webwork</servlet-name>
    <url-pattern>*.action</url-pattern>
</servlet-mapping>

xwork.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xwork PUBLIC 
    "-//OpenSymphony Group//XWork 1.1.1//EN" 
    "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">

<xwork>
    <include file="webwork-default.xml" />
    <package name="test" extends="webwork-default">
        <result-types>
            <result-type default="true" name="commontemplate" class="org.commontemplate.tools.web.webwork.TemplateResult" />
        </result-types>
        <action name="index" class="com.xxx.IndexAction" method="index">
            <result name="success" type="commontemplate">/index.ctl</result>
        </action>
    </package>
</xwork>

(4) Struts2
web.xml:
<listener>
    <listener-class>org.commontemplate.tools.web.EngineInitializeListener</listener-class>
</listener>

<filter>
    <filter-name>encoding</filter-name>
    <filter-class>org.commontemplate.tools.web.EncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>encoding</filter-name>
    <url-pattern>*.action</url-pattern>
</filter-mapping>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

struts.xml:
<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts> 
    <include file="struts-default.xml" /> 
    <package name="test" extends="struts-default"> 
        <result-types> 
            <result-type default="true" name="commontemplate" class="org.commontemplate.tools.web.struts2.TemplateResult" /> 
        </result-types> 
        <action name="index" class="com.xxx.IndexAction" method="index"> 
            <result name="success" type="commontemplate">/index.ctl</result> 
        </action> 
    </package> 
</struts> 

(5) Spring/SpringMVC
...

(6) JSP
commontemplate.tld:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib PUBLIC
    "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
    "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>ct</short-name>
    <uri>http://www.commontemplate.org/taglib/template</uri>
    <display-name>Common Template</display-name>
    <description>Common Template Library</description>

    <tag>
        <name>template</name>
        <tag-class>org.commontemplate.tools.web.jsp.TemplateTag</tag-class>
        <body-content>JSP</body-content>
        <description>Common Template In JSP</description>
    </tag>
</taglib>

test.jsp:
<%@taglib uri="http://www.commontemplate.org/taglib/template" prefix="ct" %>
<ct:template>
    JSP or/and CTL...
</ct:template>


2. Config Dependency>>
(1) CommonsLogger/Log4J
commontemplate-my.properties:
@extends=org/commontemplate/tools/web/commontemplate.properties
loggerProvider=org.commontemplate.util.log.CommonsLoggerProvider()

commons-logging.properties:
logger=org.apache.commons.logging.impl.Log4JLogger

log4j.properties:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%d] %C - %m\n
log4j.logger.CommonTemplate=DEBUG

(2) OSCache
commontemplate-my.properties:
@extends=org/commontemplate/tools/web/commontemplate.properties
templateCache=org.commontemplate.standard.cache.OSCache()

oscache.properties:
cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
cache.capacity=1000

(3) EHCache
commontemplate-my.properties:
@extends=org/commontemplate/tools/web/commontemplate.properties
templateCache=org.commontemplate.standard.cache.EHCache()

ehcache.xml:
<ehcache>
    <diskStore path="java.io.tmpdir" />
    <defaultCache 
        maxElementsInMemory="10000" 
        eternal="false" 
        timeToIdleSeconds="120" 
        timeToLiveSeconds="120" 
        overflowToDisk="true" 
    />

</ehcache>

(4) TagLib
commontemplate-my.properties:
directive{textarea}=org.commontemplate.standard.web.taglib.JspTagDirectiveAdapter()
directive{textarea}.tld=textarea.tld
 

Copyright © 2007 - 2009 CommonTemplate Developer Team