Mayaaを使ってみる
Mayaaを入れてみた。
といっても難しいことは何もない。
・手順
1.Mayaaをダウンロード
以下から最新のBlank Warをダウンロード。
http://mayaa.seasar.org/downloads/index.html
WEB-INF/libにあるjarを現在のプロジェクトのWEB-INF/libにコピーする。
2.web.xmlを編集
こんな感じ。
<?xml version="1.0"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>T2 Application Example</display-name> <context-param> <param-name>t2.encoding</param-name> <param-value>UTF-8</param-value> </context-param> <filter> <filter-name>uploadFilter</filter-name> <filter-class>org.t2framework.t2.filter.MultiPartRequestFilter </filter-class> <init-param> <param-name>uploadMaxSize</param-name> <param-value>100m</param-value> </init-param> <init-param> <param-name>uploadMaxFileSize</param-name> <param-value>100m</param-value> </init-param> <init-param> <param-name>uploadThresholdSize</param-name> <param-value>100k</param-value> </init-param> <init-param> <param-name>uploadRepositoryPath</param-name> <param-value>C:/temp/</param-value> </init-param> </filter> <filter> <filter-name>t2</filter-name> <filter-class>org.t2framework.t2.filter.T2Filter</filter-class> <init-param> <param-name>t2.rootpackage</param-name> <param-value>org.t2framework.samples.todo.page</param-value> </init-param> <init-param> <param-name>t2.config</param-name> <param-value>lucy-config.xml</param-value> </init-param> <init-param> <param-name>t2.container.adapter</param-name> <param-value>org.t2framework.t2.adapter.LucyContainerAdapter</param-value> </init-param> <init-param> <param-name>t2.eagerload</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>t2.exclude-resources</param-name> <param-value>css, js</param-value> </init-param> </filter> <filter-mapping> <filter-name>uploadFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>t2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>MayaaServlet</servlet-name> <servlet-class>org.seasar.mayaa.impl.MayaaServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>MayaaServlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
3.Pageを編集
@RequestScope @Page("employee") public class EmployeePage { private EmployeeService employeeService; ・・・ @GET @ActionPath("list") public Navigation list(WebContext context) { List<Employee> employees = employeeService.findAll(); context.getRequest().setAttribute("employees", employees); return Forward.to("/WEB-INF/pages/list.html"); } ・・・ @Inject public void setEmployeeService(EmployeeService employeeService) { this.employeeService = employeeService; } }
4.html,mayaaを編集
list.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title></title> </head> <body> <div id="employeeList"> <span id="ename">name</span><br /> </div> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <m:mayaa xmlns:m="http://mayaa.seasar.org"> <m:forEach m:id="employeeList" items="${employees}" var="item" /> <m:write id="ename" value="${item.ename}"/> </m:mayaa>