For faster navigation, this Iframe is preloading the Wikiwand page for Apache Wicket.

Apache Wicket

Apache Wicket
開発元 Apacheソフトウェア財団
最新版
9.2.0 / 2020年11月19日 (3年前) (2020-11-19)[1]
リポジトリ ウィキデータを編集
プラットフォーム クロスプラットフォーム
種別 Webアプリケーションフレームワーク
ライセンス Apache License 2.0
公式サイト http://wicket.apache.org
テンプレートを表示

Apache Wicket(アパッチ・ウィケット)は、Apacheソフトウェア財団のApache Wicketプロジェクトにて開発されているオープンソースJava Webアプリケーションフレームワークである。単にWicketと呼ばれることが多い。本頁では以下、Wicketと記述する。

概要

[編集]

元々はJonathan Lockeの作成したソフトウェアであり、2005年6月にVer1.0が発表された。

2007年6月にApacheのトップレベルプロジェクトになった。

類似するWebアプリケーションフレームワークとして、JavaServer FacesApache Tapestryが挙げられる。

wicketには、英語では「小さな門」「(銀行などの)格子窓口」の意味の他、クリケットで使用される「3本の杭と、杭の上部に2本の横木を乗せた柱状のもの」(三柱門)の意味がある。

2011年にVer1.5をリリースした後のメジャーバージョンアップは、2012年のVer6.0となる。

特徴

[編集]

Webアプリケーションフレームワークで最も普及しているもののひとつはApache Struts(以下、Struts)であったっが、StrutsはJavaで作られているにもかかわらず、Javaらしいオブジェクト指向開発を実現していない。Strutsはサーブレットを設定ファイルで制御することを目標とし、さまざまな要素を設定ファイルに記述することで、開発効率を上げようとしていた。

Wicketは、これとは逆の発想で、Javaのオブジェクト指向言語としての機能を最大限に活用できるように作られている。

Wicketから見た場合、ウェブページもオブジェクトであり、その上に置かれる文字列やタグなどもすべてオブジェクトとして取り扱う。そのため、Javaプログラムによってウェブページを継承したり、機能を委譲したり、独自に拡張することができる。

Wicketが利用する定義ファイルは、Java Servletの仕様で必要と定められているweb.xmlのみである。

画面定義やページ・テンプレートはHTMLファイル、またはXHTMLファイルで行う。Wicketが独自拡張したタグはHTMLタグの置き換えや処理を記述するのではなく、Wicketが解釈する範囲指定、意味にづけになっている。また、HTMLタグに独自拡張した属性を必要に応じて記述する。このため、JSPファイルと異なり、通常のブラウザで表示させたりAdobe DreamweaverのようなWebオーサリングツールで表示、編集することが容易である。

Wicket 独自拡張

[編集]

Wicketが独自に拡張したタグには以下のものがある。

  • wicket:link
  • wicket:panel
  • wicket:fragment
  • wicket:border
  • wicket:body
  • wicket:extend
  • wicket:child
  • wicket:message
  • wicket:remove
  • wicket:head
  • wicket:enclosure
  • wicket:container

Wicketが独自に拡張した属性には以下のものがある。

  • wicket:id
  • wicket:message
  • wicket:enclosure
  • wicket:for
  • wicket:unknown
  • wicket:scope

プログラム例

[編集]

Hello worldを表示するプログラム例を以下に示す。

HelloWorld.html
テンプレートとなるXHTMLファイル。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
      xml:lang="ja" lang="ja">
<body>
    <span wicket:id="message" id="message">ここにメッセージが表示される。</span>
</body>
</html>
HelloWorld.java
ページ・クラス。クラス名と同じ名前のHTML/XHTMLテンプレート(この場合、HelloWorld.html)を読み込む。
テンプレート中にあるwicket:id属性が"message"となっているタグの内容を指定した文字列("ハロー・ワールド!")に置き換える。
package org.wikipedia.ja.wicket;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class HelloWorld extends WebPage {
    /**
     * Constructor
     */
    public HelloWorld() {
        add(new Label("message", "ハロー・ワールド!"));
    }
}
HelloWorldApplication.java
Applicationオブジェクト。
アプリケーションをWebコンテナにロードするときの開始点となる。
package org.wikipedia.ja.wicket;

import org.apache.wicket.protocol.http.WebApplication;

public class HelloWorldApplication extends WebApplication {
    /**
     * Constructor.
     */
    public HelloWorldApplication() {
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    public Class getHomePage() {
        return HelloWorld.class;
    }
}
web.xml
Wicketサーブレット・クラスを定義し、クラスにアプリケーション・クラス名をパラメーターとして指定する。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
    <display-name>Wicket Example</display-name>
    <filter>
        <filter-name>HelloWorldApplication</filter-name>
        <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
        <init-param>
            <param-name>applicationClassName</param-name>
            <param-value>org.wikipedia.ja.wicket.HelloWorldApplication</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>HelloWorldApplication</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>


脚注

[編集]

参考書籍

[編集]
  • 「オープンソース徹底活用 WicketによるWebアプリケーション開発」 矢野勉 ISBN 978-4798022215

関連項目

[編集]

外部リンク

[編集]
{{bottomLinkPreText}} {{bottomLinkText}}
Apache Wicket
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?