ここでは、「Wicket PropertyModel で、WebPage と データ を分離する」に、日付の入力補助をする DatePicker? を付け加えてみる。
<?xml version="1.0"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.snail</groupId>
<artifactId>HelloWicket</artifactId>
<packaging>war</packaging>
<name>quickstart</name>
<version>1.0-SNAPSHOT</version>
<description></description>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/java</directory>
<includes>
<include>**</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6.0</source>
<target>6.0</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-extensions</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-datetime</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<jetty.version>6.1.4</jetty.version>
<wicket.version>1.3.0</wicket.version>
</properties>
</project>
package com.snail;
import org.apache.wicket.PageParameters;
import org.apache.wicket.extensions.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DatePicker;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.PropertyModel;
/**
* Home page.
*/
public class HomePage extends WebPage {
private static final long serialVersionUID = 3598788934381254916L;
private Form form = new Form("f") {
private static final long serialVersionUID = -1700095884500348972L;
@Override
protected void onSubmit() {
ResultPage result = new ResultPage(diary);
setResponsePage(result);
}
};
private DiaryVO diary;
private FeedbackPanel feedback = new FeedbackPanel("msg");
public HomePage(final PageParameters parameters) {
this(new DiaryVO());
}
public HomePage(final DiaryVO pDiary) {
this.diary = pDiary;
add(feedback);
add(form);
TextField txtSubject = new TextField("subject",
new PropertyModel(diary, DiaryVO.SUBJECT));
txtSubject.setRequired(true);
form.add(txtSubject);
DropDownChoice cmbType = new DropDownChoice("type",
new PropertyModel(diary, DiaryVO.TYPE), diary.getTypeList());
cmbType.setRequired(true);
form.add(cmbType);
// !!! CHANGED BELOW !!!
DateTextField txtDate = new DateTextField("date",
new PropertyModel(diary, DiaryVO.DATE));
txtDate.setRequired(true);
txtDate.add(new DatePicker());
form.add(txtDate);
// !!! CHANGED ABOVE !!!
TextArea txtArticle = new TextArea("article", new PropertyModel(diary,
DiaryVO.ARTICLE));
txtArticle.setRequired(true);
form.add(txtArticle);
}
}
すばらしい!!!
The DatePicker component has been removed from the wicket-extensions package, as it conflicts with the Apache license. There are two options for migration: * A drop-in replacement (same component) provided by Wicket Stuff. * A new date picker based on the Yahoo UI library, which is available in the wicket-datetime package. Find it under wicket.extensions.yui.calendar.DateField (see also DateTimeField and CalendarPopup for other useful components).と言うことらしい
DateTextField txtDate = new DateTextField("date", new PropertyModel(diary, DiaryVO.DATE),"yyyy年MM月dd日");