接上例所述:http://blog.csdn.net/kunshan_shenbin/archive/2008/10/31/3193529.aspx
其实Teeda还支持HTML模板。
建立工程如下图:
所需lib列表如下:
aopalliance-1.0.jar
commons-collections-3.1.jar
commons-el-1.0.jar
commons-fileupload-1.2.jar
commons-io-1.3.2.jar
commons-lang-2.1.jar
commons-logging-1.1.jar
geronimo-jta_1.1_spec-1.0.jar
javassist-3.4.ga.jar
jcaptcha-all-1.0-RC6.jar
jstl-1.1.2.jar
log4j-1.2.13.jar
ognl-2.6.9-patch-20070908.jar
poi-3.0-FINAL.jar
portlet-api-1.0.jar
s2-extension-2.4.28.jar
s2-framework-2.4.28.jar
s2-tiger-2.4.28.jar
teeda-ajax-1.0.13-sp4.jar
teeda-tiger-1.0.13-sp4.jar
xercesImpl-2.6.2.jar
xmlParserAPIs-2.6.2.jar
teeda-core-1.0.13-sp4.jar
teeda-extension-1.0.13-sp4.jar
代码依次为:
HogeOutputRenderer.java
- package com.teeda.render;
- import java.io.IOException;
- import javax.faces.component.html.HtmlOutputText;
- import javax.faces.context.FacesContext;
- import org.seasar.teeda.extension.render.html.THtmlOutputTextRenderer;
- public class HogeOutputRenderer extends THtmlOutputTextRenderer {
- public HogeOutputRenderer() {
- System.out.println("hogehoge");
- }
- protected void encodeHtmlOutputTextEnd(FacesContext arg0,
- HtmlOutputText arg1) throws IOException {
- System.out.println("encodeHtmlOutputTextEnd");
- super.encodeHtmlOutputTextEnd(arg0, arg1);
- }
- }
AddPage.java
- package com.teeda.web.add;
- import org.seasar.teeda.extension.annotation.validator.GreaterThanConstant;
- public class AddPage {
- @GreaterThanConstant
- private int arg1;
- @GreaterThanConstant
- private int arg2;
- private int result;
- public void initialize() {
- System.out.println("add init");
- }
- public void prerender() {
- System.out.println("add prerender");
- }
- public int getArg1() {
- return arg1;
- }
- public void setArg1(int arg1) {
- this.arg1 = arg1;
- }
- public int getArg2() {
- return arg2;
- }
- public void setArg2(int arg2) {
- this.arg2 = arg2;
- }
- public int getResult() {
- return result;
- }
- public void setResult(int result) {
- this.result = result;
- }
- public String doOnceCalculate() {
- result = arg1 + arg2;
- return null;
- }
- public boolean isArg1Disabled() {
- return false;
- }
- }
HelloPage.java
- package com.teeda.web.hello;
- public class HelloPage {
- public String hoge = "Teeda";
- public Class<?> initialize() {
- return null;
- }
- public Class<?> prerender() {
- return null;
- }
- public String getLayout() {
- return null;
- }
- }
app_aop.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components namespace="app_aop">
- <include path="convention.dicon"/>
- <component name="actionSupportInterceptor" class="org.seasar.teeda.extension.interceptor.ActionSupportInterceptor" />
- </components>
app.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <include path="convention.dicon"/>
- <include path="aop.dicon"/>
- <include path="app_aop.dicon"/>
- <include path="teedaExtension.dicon"/>
- </components>
appMessages_ja.properties与appMessages.properties暂为空。
convention.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <component class="org.seasar.framework.convention.impl.NamingConventionImpl">
- <initMethod name="addRootPackageName">
- <arg>"com.teeda"</arg>
- </initMethod>
- </component>
- </components>
creator.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <include path="convention.dicon"/>
- <include path="customizer.dicon"/>
- <component class="org.seasar.framework.container.creator.ActionCreator"/>
- <component class="org.seasar.framework.container.creator.DaoCreator"/>
- <component class="org.seasar.framework.container.creator.DtoCreator"/>
- <component class="org.seasar.framework.container.creator.DxoCreator"/>
- <component class="org.seasar.framework.container.creator.HelperCreator"/>
- <component class="org.seasar.framework.container.creator.LogicCreator"/>
- <component class="org.seasar.framework.container.creator.PageCreator"/>
- <component class="org.seasar.framework.container.creator.ServiceCreator"/>
- <component class="org.seasar.framework.container.creator.InterceptorCreator"/>
- <component class="org.seasar.framework.container.creator.ValidatorCreator"/>
- <component class="org.seasar.framework.container.creator.ConverterCreator"/>
- </components>
customizer.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <include path="default-customizer.dicon"/>
- <component name="commandAspectCustomizer" class="org.seasar.framework.container.customizer.AspectCustomizer">
- <property name="interceptorName">"aop.classLoaderAwareTraceInterceptor"</property>
- <property name="pointcut">"do.*, initialize, prerender"</property>
- </component>
- <component name="actionSupportAspectCustomizer" class="org.seasar.framework.container.customizer.AspectCustomizer">
- <property name="interceptorName">"app_aop.actionSupportInterceptor"</property>
- <property name="pointcut">"do.*, initialize, prerender"</property>
- </component>
- <component name="actionCustomizer" class="org.seasar.framework.container.customizer.CustomizerChain">
- <initMethod name="addCustomizer">
- <arg>commandAspectCustomizer</arg>
- </initMethod>
- <initMethod name="addCustomizer">
- <arg>actionSupportAspectCustomizer</arg>
- </initMethod>
- </component>
- </components>
env.txt
log4j.properties
- log4j.category.org.seasar=DEBUG, C
- log4j.additivity.org.seasar=false
- log4j.category.examples=DEBUG, C
- log4j.additivity.examples=false
- log4j.appender.C=org.apache.log4j.ConsoleAppender
- log4j.appender.C.Target=System.out
- log4j.appender.C.ImmediateFlush=true
- log4j.appender.C.layout=org.apache.log4j.PatternLayout
- log4j.appender.C.layout.ConversionPattern=%-5p %d [%t] %m%n
- log4j.rootLogger=INFO, A1
- log4j.appender.A1=org.apache.log4j.ConsoleAppender
- log4j.appender.A1.layout=org.apache.log4j.PatternLayout
- log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
s2container.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <include condition="#ENV == 'ut'" path="warmdeploy.dicon"/>
- <include condition="#ENV == 'ct'" path="hotdeploy.dicon"/>
- <include condition="#ENV != 'ut' and #ENV != 'ct'" path="cooldeploy.dicon"/>
- </components>
teedaCustomize.dicon
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
- "http://www.seasar.org/dtd/components24.dtd">
- <components>
- <component class="org.seasar.teeda.core.render.DefaultComponentIdLookupStrategy">
- <property name="cooperateWithForeach">true</property>
- </component>
-
-
- <component class="org.seasar.teeda.core.application.impl.DefaultComponentLookupStrategy" />
- <component class="org.seasar.teeda.extension.util.TreeNavigationImageLocatorImpl">
- <property name="imageRoot">"/img/"</property>
- </component>
- <component class="org.seasar.teeda.core.util.DefaultCancelHandler">
- <initMethod name="addCancellableException">
- <arg>@java.net.SocketException@class</arg>
- </initMethod>
- </component>
- <component class="org.seasar.teeda.extension.util.TeedaExtensionConfiguration">
-
- <property name="outputTextSpanOnly">false</property>
-
- <property name="outputTextLabelUnderAnchorOnly">false</property>
-
- <property name="disableLabelFactory">false</property>
-
- <property name="outputForEachIfEmptyItems">false</property>
- </component>
- </components>
view/add/add.html
- <?xml version="1.0" encoding="UTF-8"?>
- <!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"
- xmlns:te="http://www.seasar.org/teeda/extension"
- xmlns:h="http://java.sun.com/jsf/html"
- xml:lang="ja" lang="ja">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title id="aaa">Add</title>
- <style>
- .onTeedaError {
- background-color: #FFCCCC;
- }
- </style>
- </head>
- <body>
- <form id="addForm" action="dummy.html">
- <div>
- <span id="messages"></span>
- </div>
- <table>
- <tr>
- <td></td><td><input type="text" id="arg1" title="INPUT1" disabled="disabled"/></td>
- <td><span id="arg1Message"></span></td>
- </tr>
- <tr>
- <td> + </td>
- <td><input type="text" id="arg2" title="INPUT2"/></td>
- <td><span id="arg2Message"></span></td>
- </tr>
- <tr>
- <td> = </td>
- <td><span id="result"></span></td>
- </tr>
- </table>
- <input type="submit" value="calculate" id="doOnceCalculate" te:renderJs="true"/>
- </form>
- </body>
- </html>
view/hello/hello.html
- <?xml version="1.0" encoding="UTF-8"?>
- <!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" xml:lang="ja" lang="ja">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Teeda Extension samples</title>
- </head>
- <body>
- <form id="startForm">
- <span id="hoge">hoge</span>
- </form>
- </body>
- </html>
faces-config.xml
- <?xml version="1.0"?>
- <!DOCTYPE faces-config PUBLIC
- "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
- "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
- <faces-config>
- <application>
- <message-bundle>appMessages</message-bundle>
- <locale-config>
- <default-locale>en</default-locale>
- <supported-locale>ja</supported-locale>
- </locale-config>
- </application>
- <render-kit>
- <renderer>
- <component-family>javax.faces.Output</component-family>
- <renderer-type>org.seasar.teeda.extension.HtmlOutputText</renderer-type>
- <renderer-class>
- com.teeda.render.HogeOutputRenderer
- </renderer-class>
- </renderer>
- </render-kit>
-
- </faces-config>
web.xml
index.jsp
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>Teeda html example</title>
- </head>
- <body>
- <ul>
- <li>
- <a href="./view/hello/hello.html">Hello</a>
- </li>
- <li>
- <a href="./view/add/add.html">Add</a>
- </li>
- </ul>
- </body>
- </html>
上例实现了helloworld示例以及一个简单的加法演示程序。
请注意:
1.teedaCustomize.dicon配置文件是必须的,否则运行期会报一些很奇怪的错误。
2.在这个框架下路径名和Java文件名是有规定的。
譬如加法演示程序add:
在convention.dicon中设置RootPackageName后,必须在这个路径下的web目录下add子目录下新建AddPage.java文件。对于view层,静态的html所处的是view/add/add.html,前后必须对应起来。
3.这个框架在性能上似乎仍有很长的路要走。