Wicekt Quick Start で作った、一番簡単な Wicket アプリケーションを読んで、Wicket の基本的な仕組みを理解する。
Quick Start は、このような構造になっている:
まずは、Java EE アプリケーションの中心となる web.xml を見てみる
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>HelloWicket</display-name>
<filter>
<filter-name>wicket.HelloWicket</filter-name>
<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
<init-param>
<param-name>applicationClassName</param-name>
<param-value>com.snail.WicketApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>wicket.HelloWicket</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
--------+------------------------------------------------------------+--------- USER |WebPages (Javaクラス + HTML) | ↑ Program +------------------------------------------------------------+ Wicket --------|WebApp (org.apache.wicket.protocol.http.WebApplication) | Framework +------------------------------------------------------------+ ↓ DONNE |Filter(org.apache.wicket.protocol.http.WicketFilter) |--------- Program +------------------------------------------------------------+ ↑ |Java EE | Java EE +------------------------------------------------------------+ Framework |Java VM | ↓ --------+------------------------------------------------------------+---------
次に、ユーザプログラムの起点となる WicketApplication?.java を見てみる。
package com.snail;
import org.apache.wicket.protocol.http.WebApplication;
/**
* Application object for your web application.
* If you want to run this application without deploying,
* run the Start class.
*
* @see wicket.myproject.Start#main(String[])
*/
public class WicketApplication extends WebApplication
{
/**
* Constructor
*/
public WicketApplication()
{
}
/**
* @see wicket.Application#getHomePage()
*/
@SuppressWarnings("unchecked")
@Override
public Class getHomePage()
{
return HomePage.class;
}
}
Wicket では、同じパッケージ配下にある Javaクラスと HTML の組が Web Page になる。
<?xml version="1.0" encoding="UTF-8"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/">
<head>
<title>Wicket Quickstart Archetype Homepage</title>
</head>
<body>
<strong>Wicket Quickstart Archetype Homepage</strong>
<br/><br/>
<span wicket:id="message">message will be here</span>
</body>
</html>
package com.snail;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.WebPage;
/**
* Homepage
*/
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
// TODO Add any page properties or variables here
/**
* Constructor that is invoked when page is invoked without a session.
*
* @param parameters Page parameters
*/
public HomePage(final PageParameters parameters) {
// Add the simplest type of label
add(new Label("message", "If you see this message wicket is properly configured and running"));
// TODO Add your page's components here
}
}