日系框架之seasar2(Teeda:S2JSF的孪生兄弟)

官方主页:http://teeda.seasar.org/ja/

目前,S2JSF也使用Teeda作为JSF的底层API.

如下图所示建立工程:

所需要的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
javassist-3.4.ga.jar
jstl-1.1.2.jar
log4j-1.2.13.jar
ognl-2.6.9-patch-20070624.jar
poi-3.0-FINAL.jar
portlet-api-1.0.jar
s2-extension-2.4.28.jar
s2-framework-2.4.28.jar
teeda-ajax-1.0.13-sp4.jar
teeda-core-1.0.13-sp4.jar
teeda-extension-1.0.13-sp4.jar
xercesImpl-2.6.2.jar
xmlParserAPIs-2.6.2.jar

代码如下:

HelloBean.java

  1. package com.teeda.bean;
  2. public class HelloBean {
  3.     private String hello_ = "hello Teeda!";
  4.     public String getHello() {
  5.         return hello_;
  6.     }
  7.     public void setHello(String hello) {
  8.         hello_ = hello;
  9.     }   
  10. }

bundle.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 name="tutorialMessages" class="org.seasar.teeda.core.util.MessageBundle">
  6.         <arg>"tutorialMessages"</arg>
  7.     </component>
  8. </components>
hello.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 name="helloDto" class="com.teeda.dto.HelloDto"/>
  6. </components>

HelloDto.java

  1. package com.teeda.dto;
  2. import java.io.Serializable;
  3. public class HelloDto implements Serializable  {
  4.     private static final long serialVersionUID = 1L;
  5.     private String hello_ = "hello Teeda x DI!";
  6.     public String getHello() {
  7.         return hello_;
  8.     }
  9.     public void setHello(String hello) {
  10.         hello_ = hello;
  11.     }
  12. }

ErrorPageException.java

  1. package com.teeda.exception;
  2. public class ErrorPageException extends RuntimeException {
  3.     private static final long serialVersionUID = 1L;
  4. }

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="teeda.dicon"/>
  7.     <include path="com/teeda/dicon/bundle.dicon"/>
  8.     <include path="com/teeda/dicon/hello.dicon"/>
  9.     <component
  10.         name="teeda_errorFinder"
  11.         class="org.seasar.teeda.core.util.ErrorMessageFinder"
  12.         instance="application"
  13.     />
  14.     <component
  15.         class="org.seasar.teeda.core.render.autoregister.TeedaRendererComponentAutoRegister">
  16.         <initMethod name="addReferenceClass">
  17.             <arg>@org.seasar.teeda.extension.render.html.HtmlTextRenderer@class</arg>
  18.         </initMethod>
  19.         <initMethod name="addClassPattern">
  20.             <arg>"org.seasar.teeda.extension.render"</arg>
  21.             <arg>"..*Renderer"</arg>
  22.         </initMethod>
  23.         <initMethod name="addIgnoreClassPattern">
  24.             <arg>"org.seasar.teeda.extension.render"</arg>
  25.             <arg>"Abstract..*Renderer"</arg>
  26.         </initMethod>
  27.     </component>
  28. </components>

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. </components>

log4j.properties

  1. log4j.category.org.seasar=DEBUG, C
  2. log4j.category.com.gargoylesoftware=DEBUG, C
  3. log4j.category.org.apache.commons.httpclient=INFO, C
  4. log4j.category.httpclient.wire=INFO, C
  5. log4j.additivity.org.seasar=false
  6. log4j.appender.C=org.apache.log4j.ConsoleAppender
  7. log4j.appender.C.Target=System.out
  8. log4j.appender.C.ImmediateFlush=true
  9. log4j.appender.C.layout=org.apache.log4j.PatternLayout
  10. #log4j.appender.C.layout.ConversionPattern=%-5p %d [%t] %m%n
  11. log4j.appender.C.layout.ConversionPattern=%-5p %d{ABSOLUTE} [%t] %m%n

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.     <component class="org.seasar.teeda.core.application.impl.DefaultComponentLookupStrategy" />
  7. </components>

teedaErrorPage.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="teedaErrorPage" >
  5.     <component class="org.seasar.teeda.core.util.ServletErrorPageManagerImpl">
  6.         <initMethod name="addErrorPage">
  7.             <arg>@com.teeda.exception.ErrorPageException@class</arg>
  8.             <arg>"/faces/errorpage/errorPage.jsp"</arg>
  9.         </initMethod>
  10.     </component>
  11. </components>

tutorialMessages_en.properties

  1. aaa=ABCDE
  2. bbb=Foo

tutorialMessages_ja.properties

  1. aaa=あいうえお
  2. bbb=ほげ

tutorialMessages.properties

  1. aaa=ABCDE_default
  2. bbb=Foo_default

errorpage/errorPage.jsp

  1. <%@ page contentType="text/html; charset=UTF-8" %>
  2. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  3. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  4. <html>
  5. <head>
  6. <title>errorPage.jsp</title>
  7. </head>
  8. <body>
  9. <f:view>
  10.     error occured.
  11. </f:view>
  12. </body>
  13. </html>

hello/hello.jsp

  1. <%@ page contentType="text/html; charset=UTF-8" %>
  2. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  3. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  4. <html>
  5. <head>
  6. <title>hello</title>
  7. </head>
  8. <body>
  9. <f:view>
  10.   <h:outputText value="#{helloBean.hello}"/>
  11. </f:view>
  12. </body>
  13. </html>

hello/helloDI.jsp

  1. <%@ page contentType="text/html; charset=UTF-8" %>
  2. <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  3. <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
  4. <html>
  5. <head>
  6. <title>hello x DI</title>
  7. </head>
  8. <body>
  9. <f:view>
  10.   <h:outputText value="#{helloDto.hello}"/>
  11. </f:view>
  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.   
  6. <faces-config>
  7.     <application>
  8.         <message-bundle>examples.teeda.message.Messages</message-bundle>
  9.         <locale-config>
  10.             <default-locale>en</default-locale>
  11.             <supported-locale>ja</supported-locale>
  12.         </locale-config>
  13.     </application>
  14.     <lifecycle>
  15.         <phase-listener>org.seasar.teeda.core.event.PhaseChangeTracer</phase-listener>
  16.     </lifecycle>
  17.     <managed-bean>
  18.         <managed-bean-name>helloBean</managed-bean-name>
  19.         <managed-bean-class>com.teeda.bean.HelloBean</managed-bean-class>
  20.         <managed-bean-scope>request</managed-bean-scope>
  21.     </managed-bean>
  22. </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.DEFAULT_SUFFIX</param-name>
  8.         <param-value>.jsp</param-value>
  9.     </context-param>
  10.     <context-param>
  11.         <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  12.         <param-value>server</param-value>
  13.     </context-param>
  14.     <context-param>
  15.         <param-name>teeda.JAVASCRIPT_NOT_PERMITTED_PATH</param-name>
  16.         <param-value>/link_no_js</param-value>
  17.     </context-param>
  18.     <filter>
  19.         <filter-name>s2filter</filter-name>
  20.         <filter-class>org.seasar.framework.container.filter.S2ContainerFilter</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>extensionfilter</filter-name>
  32.         <filter-class>org.seasar.teeda.extension.filter.ExtensionFilter</filter-class>
  33.     </filter>
  34.     <filter-mapping>
  35.         <filter-name>s2filter</filter-name>
  36.         <url-pattern>/*</url-pattern>
  37.     </filter-mapping>
  38.     <filter-mapping>
  39.         <filter-name>encodingfilter</filter-name>
  40.         <url-pattern>*.jsp</url-pattern>
  41.     </filter-mapping>
  42.     <filter-mapping>
  43.         <filter-name>extensionfilter</filter-name>
  44.         <url-pattern>/teedaExtension/*</url-pattern>
  45.     </filter-mapping>
  46.     <servlet>
  47.         <servlet-name>teedaServlet</servlet-name>
  48.         <servlet-class>org.seasar.teeda.core.webapp.TeedaServlet</servlet-class>
  49.         <load-on-startup>1</load-on-startup>
  50.     </servlet>
  51.     <servlet>
  52.         <servlet-name>Faces Servlet</servlet-name>
  53.         <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  54.         <load-on-startup>2</load-on-startup>
  55.     </servlet>
  56.     <servlet>
  57.         <servlet-name>AjaxServlet</servlet-name>
  58.         <servlet-class>org.seasar.teeda.ajax.AjaxServlet</servlet-class>
  59.         <load-on-startup>3</load-on-startup>
  60.     </servlet>
  61.     <servlet-mapping>
  62.         <servlet-name>teedaServlet</servlet-name>
  63.         <url-pattern>/teedaServlet</url-pattern>
  64.     </servlet-mapping>
  65.     <servlet-mapping>
  66.         <servlet-name>Faces Servlet</servlet-name>
  67.         <url-pattern>/faces/*</url-pattern>
  68.     </servlet-mapping>
  69.     <servlet-mapping>
  70.         <servlet-name>AjaxServlet</servlet-name>
  71.         <url-pattern>*.ajax</url-pattern>
  72.     </servlet-mapping>
  73.     <welcome-file-list>
  74.         <welcome-file>index.html</welcome-file>
  75.     </welcome-file-list>
  76. </web-app>

index.html

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <title>Teeda Example</title>
  5. </head>
  6. <body>
  7. <h1>Welcome to Teeda Example</h1>
  8. <hr/>
  9. <div>
  10. <hr/>
  11. </div>
  12. <ul>
  13. <li>
  14.     <a href="faces/hello/hello.jsp">hello</a><br/>
  15. </li>
  16. <li>
  17.     <a href="faces/hello/helloDI.jsp">hello x DI</a><br/>
  18. </li>
  19. </ul>
  20. <div>
  21. <hr/>
  22. </div>
  23. </body>
  24. </html>

上面的例子包含了一个普通的JSF例子,以及一个使用了Seasar注入的JSF例子。

其实Teeda项目就是在JSF的基础上整合了Seasar的DI功能,框架本身与S2JSF定位基本上是一致的。

如今S2JSF的维护一直处于停滞状态,而Teeda则版本更新很快。可能Teeda才是Seasar团队将来在整合JSF上做出的选择。

你可能感兴趣的:(框架,JSF,application,Class,encoding)