improved atmosphere example
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ce1089c8 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ce1089c8 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ce1089c8 Branch: refs/heads/sandbox/atmosphere Commit: ce1089c8896b0a5381357456e4729d4b62708261 Parents: 42678b1 Author: Emond Papegaaij <[email protected]> Authored: Fri May 4 10:13:12 2012 +0200 Committer: Emond Papegaaij <[email protected]> Committed: Fri May 4 10:13:12 2012 +0200 ---------------------------------------------------------------------- .../wicket/examples/atmosphere/HomePage.html | 65 ++++----------- .../wicket/examples/atmosphere/HomePage.java | 36 +++++++- 2 files changed, 49 insertions(+), 52 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/ce1089c8/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.html ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.html b/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.html index 69ff0e5..03dbd4a 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.html +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.html @@ -1,51 +1,20 @@ <!DOCTYPE html> <html xmlns:wicket="http://wicket.apache.org"> - <head> - <meta charset="utf-8" /> - <title>Apache Wicket Quickstart</title> - <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:regular,bold' rel='stylesheet' type='text/css' /> - <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="Stylesheet" /> - </head> - <body> - <div id="hd"> - <div id="logo"> - <img src="logo.png" width="50px" height="50px" alt="Wicket Logo" /> - <h1>Apache Wicket</h1> - </div> - </div> - <div id="bd"> - <h2>Congratulations!</h2> - <p> - Your quick start works! This project is especially useful to - start developing your Wicket application or to create a test - case for a bug report. - </p> - <h3>Get help</h3> - <p> - We are here to help! - </p> - <ul> - <li>join us on IRC on <a href="irc:%23%[email protected]">##[email protected]</a></li> - <li><a href="http://wicket-users.markmail.org/" target="_blank" title="Search the mailing list archives">search</a> our mailing list archives</li> - <li>ask a question on the <a href="http://wicket.apache.org/help/email.html">users list</a></li> - </ul> - <h3>Reporting a bug</h3> - <p> - Help us help you: - </p> - <ol> - <li>reproduce the bug with the <strong>least</strong> amount of code</li> - <li>create a unit test that shows the bug</li> - <li>fix the bug and create a patch</li> - <li>attach the result of step 1, 2 or 3 to a <a href="https://issues.apache.org/jira/browse/WICKET" target="_blank">JIRA issue</a></li> - <li>profit!</li> - </ol> - <p> - Please mention the correct Wicket version: <wicket:container wicket:id="version">1.5-SNAPSHOT</wicket:container>. - </p> - <p wicket:id="time"></p> - </div> - <div id="ft"> - </div> - </body> +<head> +<title>Wicket Examples - atmosphere</title> +<link rel="stylesheet" type="text/css" href="style.css" /> +</head> +<body> + <span wicket:id="mainNavigation"></span> + <p> + The current time is: <span wicket:id="time"></span> + </p> + <p> + Message received: <span wicket:id="message"></span> + </p> + <form wicket:id="form"> + <input wicket:id="input"> <a href="#" wicket:id="send">Send + message</a> + </form> +</body> </html> http://git-wip-us.apache.org/repos/asf/wicket/blob/ce1089c8/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.java b/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.java index f89dc95..f53221a 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/atmosphere/HomePage.java @@ -20,29 +20,57 @@ import java.util.Date; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.atmosphere.EventBus; import org.apache.wicket.atmosphere.Subscribe; -import org.apache.wicket.markup.html.WebPage; +import org.apache.wicket.examples.WicketExamplePage; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.Model; import org.apache.wicket.request.mapper.parameter.PageParameters; -public class HomePage extends WebPage +public class HomePage extends WicketExamplePage { private static final long serialVersionUID = 1L; private Component timeLabel; + private Component messageLabel; + private TextField<String> input; public HomePage(final PageParameters parameters) { - add(new Label("version", getApplication().getFrameworkSettings().getVersion())); add(timeLabel = new Label("time", Model.of("start")).setOutputMarkupId(true)); + add(messageLabel = new Label("message", Model.of("-")).setOutputMarkupId(true)); + + Form<Void> form = new Form<Void>("form"); + add(form); + form.add(input = new TextField<String>("input", Model.of(""))); + form.add(new AjaxLink<Void>("send") + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick(AjaxRequestTarget target) + { + EventBus.get().post(input.getModelObject()); + } + }); + setVersioned(false); } @Subscribe - public void test(AjaxRequestTarget target, Date event) + public void updateTime(AjaxRequestTarget target, Date event) { timeLabel.setDefaultModelObject(event.toString()); target.add(timeLabel); } + + @Subscribe + public void receiveMessage(AjaxRequestTarget target, String message) + { + messageLabel.setDefaultModelObject(message); + target.add(messageLabel); + } }
