日系框架之seasar2(Teeda支援HTML模板)

接上例所述:http://blog.csdn.net/kunshan_shenbin/archive/2008/10/31/3193529.aspx

其实Teeda还支持HTML模板。

建立工程如下图:

日系框架之seasar2(Teeda支援HTML模板)_第1张图片

所需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

  1. package com.teeda.render;
  2. import java.io.IOException;
  3. import javax.faces.component.html.HtmlOutputText;
  4. import javax.faces.context.FacesContext;
  5. import org.seasar.teeda.extension.render.html.THtmlOutputTextRenderer;
  6. public class HogeOutputRenderer extends THtmlOutputTextRenderer {
  7.     public HogeOutputRenderer() {
  8.         System.out.println("hogehoge");
  9.     }
  10.     protected void encodeHtmlOutputTextEnd(FacesContext arg0,
  11.             HtmlOutputText arg1) throws IOException {
  12.         System.out.println("encodeHtmlOutputTextEnd");
  13.         super.encodeHtmlOutputTextEnd(arg0, arg1);
  14.     }
  15. }

AddPage.java

  1. package com.teeda.web.add;
  2. import org.seasar.teeda.extension.annotation.validator.GreaterThanConstant;
  3. public class AddPage {
  4.     @GreaterThanConstant
  5.     private int arg1;
  6.     @GreaterThanConstant
  7.     private int arg2;
  8.     private int result;
  9.     public void initialize() {
  10.         System.out.println("add init");
  11.     }
  12.     public void prerender() {
  13.         System.out.println("add prerender");
  14.     }
  15.     public int getArg1() {
  16.         return arg1;
  17.     }
  18.     public void setArg1(int arg1) {
  19.         this.arg1 = arg1;
  20.     }
  21.     public int getArg2() {
  22.         return arg2;
  23.     }
  24.     public void setArg2(int arg2) {
  25.         this.arg2 = arg2;
  26.     }
  27.     public int getResult() {
  28.         return result;
  29.     }
  30.     public void setResult(int result) {
  31.         this.result = result;
  32.     }
  33.     public String doOnceCalculate() {
  34.         result = arg1 + arg2;
  35.         return null;
  36.     }
  37.     public boolean isArg1Disabled() {
  38.         return false;
  39.     }
  40. }

HelloPage.java

  1. package com.teeda.web.hello;
  2. public class HelloPage {
  3.     public String hoge = "Teeda";
  4.     public Class<?> initialize() {
  5.         return null;
  6.     }
  7.     public Class<?> prerender() {
  8.         return null;
  9.     }
  10.     public String getLayout() {
  11.         return null;
  12.     }
  13. }

app_aop.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components namespace="app_aop">
  5.     <include path="convention.dicon"/>
  6.     <component name="actionSupportInterceptor" class="org.seasar.teeda.extension.interceptor.ActionSupportInterceptor" />
  7. </components>

app.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <include path="convention.dicon"/>
  6.     <include path="aop.dicon"/>
  7.     <include path="app_aop.dicon"/>
  8.     <include path="teedaExtension.dicon"/>
  9. </components>

appMessages_ja.properties与appMessages.properties暂为空。

convention.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN" 
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <component class="org.seasar.framework.convention.impl.NamingConventionImpl">
  6.         <initMethod name="addRootPackageName">
  7.             <arg>"com.teeda"</arg>
  8.         </initMethod>
  9.     </component>
  10. </components>

creator.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <include path="convention.dicon"/>
  6.     <include path="customizer.dicon"/>
  7.     <component class="org.seasar.framework.container.creator.ActionCreator"/>
  8.     <component class="org.seasar.framework.container.creator.DaoCreator"/>
  9.     <component class="org.seasar.framework.container.creator.DtoCreator"/>
  10.     <component class="org.seasar.framework.container.creator.DxoCreator"/>
  11.     <component class="org.seasar.framework.container.creator.HelperCreator"/>
  12.     <component class="org.seasar.framework.container.creator.LogicCreator"/>
  13.     <component class="org.seasar.framework.container.creator.PageCreator"/>
  14.     <component class="org.seasar.framework.container.creator.ServiceCreator"/>
  15.     <component class="org.seasar.framework.container.creator.InterceptorCreator"/>
  16.     <component class="org.seasar.framework.container.creator.ValidatorCreator"/>
  17.     <component class="org.seasar.framework.container.creator.ConverterCreator"/>
  18. </components>

customizer.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <include path="default-customizer.dicon"/>
  6.     <component name="commandAspectCustomizer" class="org.seasar.framework.container.customizer.AspectCustomizer">
  7.         <property name="interceptorName">"aop.classLoaderAwareTraceInterceptor"</property>
  8.         <property name="pointcut">"do.*, initialize, prerender"</property>
  9.     </component>
  10.     <component name="actionSupportAspectCustomizer" class="org.seasar.framework.container.customizer.AspectCustomizer">
  11.         <property name="interceptorName">"app_aop.actionSupportInterceptor"</property>
  12.         <property name="pointcut">"do.*, initialize, prerender"</property>
  13.     </component>
  14.     <component name="actionCustomizer" class="org.seasar.framework.container.customizer.CustomizerChain">
  15.         <initMethod name="addCustomizer">
  16.             <arg>commandAspectCustomizer</arg>
  17.         </initMethod>
  18.         <initMethod name="addCustomizer">
  19.             <arg>actionSupportAspectCustomizer</arg>
  20.         </initMethod>
  21.     </component>
  22. </components>

env.txt

  1. ct

log4j.properties

  1. log4j.category.org.seasar=DEBUG, C
  2. log4j.additivity.org.seasar=false
  3. log4j.category.examples=DEBUG, C
  4. log4j.additivity.examples=false
  5. log4j.appender.C=org.apache.log4j.ConsoleAppender
  6. log4j.appender.C.Target=System.out
  7. log4j.appender.C.ImmediateFlush=true
  8. log4j.appender.C.layout=org.apache.log4j.PatternLayout
  9. log4j.appender.C.layout.ConversionPattern=%-5p %d [%t] %m%n
  10. log4j.rootLogger=INFO, A1
  11. log4j.appender.A1=org.apache.log4j.ConsoleAppender
  12. log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  13. log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

s2container.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <include condition="#ENV == 'ut'" path="warmdeploy.dicon"/>
  6.     <include condition="#ENV == 'ct'" path="hotdeploy.dicon"/>
  7.     <include condition="#ENV != 'ut' and #ENV != 'ct'" path="cooldeploy.dicon"/>
  8. </components>

teedaCustomize.dicon

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container 2.4//EN"
  3.     "http://www.seasar.org/dtd/components24.dtd">
  4. <components>
  5.     <component class="org.seasar.teeda.core.render.DefaultComponentIdLookupStrategy">
  6.         <property name="cooperateWithForeach">true</property>
  7.     </component>
  8.     <!-- JSF標準のIDの採番方式にしなくてはいけない場合は下記を使用。 -->
  9.     <!--
  10.     <component class="org.seasar.teeda.core.render.JsfSpecComponentIdLookupStrategy"/>
  11.     -->
  12.     <component class="org.seasar.teeda.core.application.impl.DefaultComponentLookupStrategy" />
  13.     <component class="org.seasar.teeda.extension.util.TreeNavigationImageLocatorImpl">
  14.         <property name="imageRoot">"/img/"</property>
  15.     </component>
  16.     <component class="org.seasar.teeda.core.util.DefaultCancelHandler">
  17.         <initMethod name="addCancellableException">
  18.             <arg>@java.net.SocketException@class</arg>
  19.         </initMethod>
  20.     </component>
  21.     <component class="org.seasar.teeda.extension.util.TeedaExtensionConfiguration">
  22.         <!-- outputText を <span> 要素の場合のみ関連づける(1.0.12互換)には以下のプロパティを true に設定 -->
  23.         <property name="outputTextSpanOnly">false</property>
  24.         <!-- <span id="~Label"> が <a> の子要素の場合のみラベルに関連づける(1.0.12互換)には以下のプロパティを true に設定 -->
  25.         <property name="outputTextLabelUnderAnchorOnly">false</property>
  26.         <!-- <label id="~"> を outputLabel に関連づけないようにするには以下のプロパティを true に設定 -->
  27.         <property name="disableLabelFactory">false</property>
  28.         <!-- itemsが空の場合でもforEachの指定された要素を出力する場合 (Teeda 1.0.13-sp1 以前と互換) は以下のプロパティを true に設定 -->
  29.         <property name="outputForEachIfEmptyItems">false</property>
  30.     </component>
  31. </components>

view/add/add.html

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" 
  4.  xmlns:te="http://www.seasar.org/teeda/extension" 
  5.  xmlns:h="http://java.sun.com/jsf/html" 
  6.  xml:lang="ja" lang="ja">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <title id="aaa">Add</title>
  10. <style>
  11. .onTeedaError {
  12.     background-color: #FFCCCC;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <form id="addForm" action="dummy.html">
  18. <div>
  19. <span id="messages"></span>
  20. </div>
  21. <table>
  22. <tr>
  23. <td></td><td><input type="text" id="arg1" title="INPUT1" disabled="disabled"/></td>
  24. <td><span id="arg1Message"></span></td>
  25. </tr>
  26. <tr>
  27. <td> + </td>
  28. <td><input type="text" id="arg2" title="INPUT2"/></td>
  29. <td><span id="arg2Message"></span></td>
  30. </tr>
  31. <tr>
  32. <td> = </td>
  33. <td><span id="result"></span></td>
  34. </tr>
  35. </table>
  36. <input type="submit" value="calculate" id="doOnceCalculate" te:renderJs="true"/>
  37. </form>
  38. </body>
  39. </html>

view/hello/hello.html

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <title>Teeda Extension samples</title>
  7. </head>
  8. <body>
  9. <form id="startForm">
  10. <span id="hoge">hoge</span>
  11. </form>
  12. </body>
  13. </html>

faces-config.xml

  1. <?xml version="1.0"?>
  2. <!DOCTYPE faces-config PUBLIC
  3.   "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
  4.   "http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
  5. <faces-config>
  6.     <application>
  7.         <message-bundle>appMessages</message-bundle>
  8.         <locale-config>
  9.             <default-locale>en</default-locale>
  10.             <supported-locale>ja</supported-locale>
  11.         </locale-config>
  12.     </application>
  13.     <render-kit>
  14.         <renderer>
  15.             <component-family>javax.faces.Output</component-family>
  16.             <renderer-type>org.seasar.teeda.extension.HtmlOutputText</renderer-type>
  17.             <renderer-class>
  18.                 com.teeda.render.HogeOutputRenderer
  19.             </renderer-class>
  20.         </renderer>
  21.     </render-kit>
  22.     
  23. </faces-config>

web.xml

  1. <?xml version="1.0"?>
  2. <!DOCTYPE web-app PUBLIC
  3.   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  4.   "http://java.sun.com/dtd/web-app_2_3.dtd">
  5. <web-app>
  6.     <context-param>
  7.         <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  8.         <param-value>server</param-value>
  9.     </context-param>
  10.     <context-param>
  11.         <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  12.         <param-value>.html</param-value>
  13.     </context-param>
  14.     <context-param>
  15.         <param-name>teeda.JAVASCRIPT_NOT_PERMITTED_PATH</param-name>
  16.         <param-value>/view/</param-value>
  17.     </context-param>
  18.     <filter>
  19.         <filter-name>extensionfilter</filter-name>
  20.         <filter-class>org.seasar.teeda.extension.filter.ExtensionFilter</filter-class>
  21.     </filter>
  22.     <filter>
  23.         <filter-name>encodingfilter</filter-name>
  24.         <filter-class>org.seasar.extension.filter.EncodingFilter</filter-class>
  25.         <init-param>
  26.             <param-name>encoding</param-name>
  27.             <param-value>UTF-8</param-value>
  28.         </init-param>
  29.     </filter>
  30.     <filter>
  31.         <filter-name>s2filter</filter-name>
  32.         <filter-class>org.seasar.framework.container.filter.S2ContainerFilter</filter-class>
  33.     </filter>
  34.     <filter>
  35.         <filter-name>hotdeployfilter</filter-name>
  36.         <filter-class>org.seasar.framework.container.hotdeploy.HotdeployFilter</filter-class>
  37.     </filter>
  38.     <filter>
  39.         <filter-name>requestDumpFilter</filter-name>
  40.         <filter-class>org.seasar.teeda.core.filter.RequestDumpFilter</filter-class>
  41.     </filter>
  42.     <filter-mapping>
  43.         <filter-name>extensionfilter</filter-name>
  44.         <url-pattern>/teedaExtension/*</url-pattern>
  45.     </filter-mapping>
  46.     <filter-mapping>
  47.         <filter-name>encodingfilter</filter-name>
  48.         <url-pattern>*.html</url-pattern>
  49.     </filter-mapping>
  50.     <filter-mapping>
  51.         <filter-name>s2filter</filter-name>
  52.         <url-pattern>*.html</url-pattern>
  53.     </filter-mapping>
  54.     <filter-mapping>
  55.         <filter-name>hotdeployfilter</filter-name>
  56.         <url-pattern>*.html</url-pattern>
  57.     </filter-mapping>
  58.     <filter-mapping>
  59.         <filter-name>requestDumpFilter</filter-name>
  60.         <url-pattern>*.html</url-pattern>
  61.     </filter-mapping>
  62.     <servlet>
  63.         <servlet-name>teedaServlet</servlet-name>
  64.         <servlet-class>org.seasar.teeda.core.webapp.TeedaServlet</servlet-class>
  65.         <init-param>
  66.             <param-name>configPath</param-name>
  67.             <param-value>app.dicon</param-value>
  68.         </init-param>
  69.         <init-param>
  70.             <param-name>debug</param-name>
  71.             <param-value>true</param-value>
  72.         </init-param>
  73.         <load-on-startup>1</load-on-startup>
  74.     </servlet>
  75.     <servlet>
  76.         <servlet-name>facesServlet</servlet-name>
  77.         <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  78.         <load-on-startup>2</load-on-startup>
  79.     </servlet>
  80.     <servlet-mapping>
  81.         <servlet-name>facesServlet</servlet-name>
  82.         <url-pattern>*.html</url-pattern>
  83.     </servlet-mapping>
  84.     <servlet-mapping>
  85.         <servlet-name>teedaServlet</servlet-name>
  86.         <url-pattern>/teedaServlet</url-pattern>
  87.     </servlet-mapping>
  88.     <welcome-file-list>
  89.         <welcome-file>index.jsp</welcome-file>
  90.     </welcome-file-list>
  91.     <error-page>
  92.         <exception-type>java.lang.Throwable</exception-type>
  93.         <location>/debug/debug.jsp</location>
  94.     </error-page>
  95. </web-app>

index.jsp

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <title>Teeda html example</title>
  5. </head>
  6. <body>
  7. <ul>
  8.     <li>
  9.         <a href="./view/hello/hello.html">Hello</a>
  10.     </li>
  11.     <li>
  12.         <a href="./view/add/add.html">Add</a>
  13.     </li>
  14. </ul>
  15. </body>
  16. </html>

上例实现了helloworld示例以及一个简单的加法演示程序。

请注意:

1.teedaCustomize.dicon配置文件是必须的,否则运行期会报一些很奇怪的错误。

2.在这个框架下路径名和Java文件名是有规定的。

譬如加法演示程序add:

    在convention.dicon中设置RootPackageName后,必须在这个路径下的web目录下add子目录下新建AddPage.java文件。对于view层,静态的html所处的是view/add/add.html,前后必须对应起来。

3.这个框架在性能上似乎仍有很长的路要走。

你可能感兴趣的:(html,框架,Class,input,Path,encoding)