Comments
Description
Transcript
ç¿`ä.. - Wicket
Wicket 2013.09.12 Hiroto Yamakawa @gishi_yama [email protected] Apache Wicket Wicket Wicket-Sapporo 6 New! Apache Wicket "...Wicket Java Java " , "Apache Wicket Web ", , pp.17 "...Apache Wicket is a Java software framework that aims to bridge the between object-oriented programming and the fact that the web is built on HTTP, which is a stateless protocol." Martijn Dashorst, Eelco Hillenius, "Wicket in Action", Manning Publications Co., pp.23 "Wicket simplifies web development and makes it fun." Igor Vaynberg, "Apache Wicket Cookbook", Packt Pablishing, pp.1 Wicket Web Java " Web Wicket Web " , "Wicket 1 Hello, Wicket", http://gihyo.jp/dev/feature/01/wicket/0001 , = Wicket General schema of page request handling for a component oriented framework Andrea D B, Carsten H, Christian K, Daniel B, "Apache Wicket User Guide", http://wicketguide.comsysto.com/guide/chapter2.html#chapter2_2 Wicket Wicket http://wicket.apache.org/ POJO XML Java Web Apache Wicket HTML Java <p>foo</p> <p>bar</p> foo, bar Web ... JSP HTML HTML (HTML ) Apache Wicket ... TestPage.html <p wicket:id="foo">foo</p> <p wicket:id="bar">bar</p> TestPage.java add(new Label("foo", new Model("こんにちは!"))); add(new Label("bar", new Model("Wicket-Sapporoへようこそ!"))); Browser <p>こんにちは!</p> <p>Wicket-Sapporoへようこそ!</p> wicket:id HTML (HTML Java ) HTML HTML POJO HTML Java XML Web.xml servlet-filter, servlet-mapping Web.xml <filter> <filter-name>MyApp</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>jp.example.MyApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>MyApp</filter-name> <!-- コンテキストパス以下はWicketの制御の対象にする場合 --> <url-pattern>/*</url-pattern> </filter-mapping> URL Java Java XML XML ... Swing CleanURL Java Wicket 6 Ajax JUnitTest Ajax JQuery i18n Html API Wicket Auth/Roles API Google Guice Spring CDI Velocity JMX Bootstrap API Web Framework Benchmarks(Round 6, Language:Java, Tests:Single Query, HardWare:i7) http://www.techempower.com/benchmarks/ JSON http://www.cafepress.com/apachewicket "Several books have been written about Apache Wicket, 5 in English, 2 in German and 1 in Japanese." (Books about Wicket, http://wicket.apache.org/learn/books/) Wicket Ver,1.4 http://www.amazon.co.jp/dp/4798022217/ Wicket Wicket User Guide ver,6 https://code.google.com/p/wicket-guide/ Wicket http://wicketguide.comsysto.com/ Wicket Wicket-JA http://www.wicket-ja.org/ Q. Wicket-Ja A. ML ML ... ... http://builtwithwicket.tumblr.com/ in Japan... e ( SNS Wicket Java POJO HTML/ XML Wicket MacOSX OS Mavan3 Jetty 1. https://github.com/gishi-yama/wicket_workshop 2. Download ZIP 3. $ cd wicket_workshop-master $ mvn package $ mvn jetty:run 4. http://localhost:8080/wiclet_workshop/ Wicket Maven Wicket QuickStart Maven http://wicket.apache.org/start/quickstart.html Maven <dependency> <groupId>org.apache.wicket</groupId> <artifactId>wicket-core</artifactId> <version>6.10.0</version> </dependency> pom.xml Wicket Maven Wicket INF/lib/ http://wicket.apache.org/ /WEB- wicket-core.jar wicket-request.jar wicket-util.jar Wicket Wicket SLF4J Wicket QuickStart SLF4J Log4J Logback http://logback.qos.ch/ http://www.slf4j.org/ SLF4J Wicket Web.xml web.xml <filter> <filter-name>MyApp</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>jp.example.MyApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>MyApp</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> filter/filter-name filter/init-param/param-value filter-mapping/url-pattern WebApplication package jp.example; public class MyApplication extends WebApplication { /* snip */ } param/param-value web.xml <init-param> <param-name>applicationClassName</param-name> <param-value>jp.example.MyApplication</param-value> </init-param> filter/init- public class MyApplication extends WebApplication { @Override public Class<? extends Page> getHomePage() { return HomePage.class; } } HomePage.class .java HTML HTML SimplePage.html <!DOCTYPE html> <html lang="ja" xmlns:wicket="http://wicket.apache.org"> <head> <meta charset="UTF-8" /> </head> <body> <p>message1 is here.</p> </body> </html> HTML wicket:id <body> <p wicket:id="label1">message1 is here.</p> </body> wicket:id HTML SimplePage.java public class SimplePage extends WebPage { public SimplePage() { } } WebPage HTML HTML Wicket HTML public class SimplePage extends WebPage { public SimplePage() { // 1. 表示したいデータ(オブジェクト)を用意する. String message1 = "こんにちは!"; // 2. 表示したいオブジェクトをModelオブジェクトでラップします IModel<String> model1 = new Model<>(message1); // 3. Modelを、対応するHTMLのwicket:id用のコンポーネントにセットします Label label1 = new Label("label1", model1); } } // 4. コンポーネントをページにaddします add(label1); HTML ... Wicket , "Apache Wicket Web ", , pp.29 HTML 1 HTML add Wicket:id http://www.wicket-library.com/wicketexamples/compref/ Label IModel<String> model = new Model<>("こんにちは!"); Label fooLabel = new Label("foo", model); add(fooLabel); MultiLineLabel Label Model IModel<String> model = new Model<>("こんにちは!\n今日も良い天気ですね!"); MultiLineLabel fooLabel = new MultiLineLabel("foo", model); add(fooLabel); Link IModel<Bean> model = new Model<>(new Bean()); Link<Bean> link = new Link<Bean>("foo", model) { private static final long serialVersionUID = 1L; @Override public void onClick() { // リンクやボタンがクリックされたときのイベント処理 // この例では、LinkにセットされたModel(中身はBeanオブジェクト)を // 次ページへ渡して遷移する setResponsePage(new NextPage(getModel())); } }; add(link); Form TextField : IModel<Bean> model = new CompoundPropertyModel<>(new Bean()); Form<Bean> form = new Form<Bean>("foo", model)) { private static final long serialVersionUID = 1L; @Override protected void onSubmit() { // Submitボタンがクリックされたときのイベント処理 // たとえば、BeanをDBに登録する、など } }; add(form); form.add(new TextField<String>("input")); ) CompoundPropertyModel TextField Bean#input Wicket HTML Form form setModel(IModel) getModel() HTML wicket:id wicket:id HTML <form wicket:id="form"> <input type="text" wicket:id="name"> </form> <p wicket:id="label">message</p> Java Form<Bean> form = new Form<Bean>("form", formModel) { /* snip */ }; // wicket:id="form" は最上位なので、ページにadd add(form); // wicket:id="name" は "form" の入れ子の位置にあるので、 // wicket:id="form" のコンポーネントであるformにadd form.add(new TextField<String>("name")); Label label = new Label("label", labelModel); // wicket:id="label" は最上位なので、ページにadd add(label); Model String str = "こんにちは"; IModel<String> model = new Model<>(str); add(new Label("foo", model); ListModel Model List<Integer> list = new ArrayList(); list.add(1); list.add(2); IModel<List<Integer> listmodel = new ListModel<>(list); CompoundPropertyModel Bean wicket:id CompoundPropertyModel IModel beanModel = new CompoundPropertyModel<>(new Bean()) setDefaultModel(beanModel); add(new Label("loginId"); add(new Label("name"); ResourceModel Java Code i18n IModel<String> beanModel = new ResourceModel("form.error"); form.error=送信エラーが発生しました。入力値を確認してください。 Serializable setObject(Object) getObject() Wicket HTML HTML HTML wicket:id Wicket