You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/12/12 14:56:04 UTC

[1/2] git commit: WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added

Updated Branches:
  refs/heads/5435-ajax-browser-info [created] 7fcbfe7bc


WICKET-5435 Ajaxified version of WebSession#getClientInfo should be added


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/90235c1c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/90235c1c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/90235c1c

Branch: refs/heads/5435-ajax-browser-info
Commit: 90235c1c2ef7eb6ffa9d5d836ce7d0a398ca2821
Parents: ba2e5ce
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 12 15:51:57 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 12 15:51:57 2013 +0200

----------------------------------------------------------------------
 Gruntfile.js                                    |   3 +-
 .../markup/html/pages/AjaxBrowserInfoForm.java  |  74 +++++++++++
 .../markup/html/pages/BrowserInfoForm.html      |  33 +----
 .../markup/html/pages/BrowserInfoForm.java      |  70 ++++++-----
 .../markup/html/pages/BrowserInfoPage.html      |   2 +-
 .../markup/html/pages/BrowserInfoPage.java      |  26 ++--
 .../markup/html/pages/wicket-browser-info.js    |  83 ++++++++++++
 .../ajaxhellobrowser/AjaxHelloBrowser.html      |  24 ++++
 .../ajaxhellobrowser/AjaxHelloBrowser.java      | 126 +++++++++++++++++++
 .../HelloBrowserApplication.java                |  33 +++++
 .../examples/hellobrowser/HelloBrowser.java     |  17 +--
 .../hellobrowser/HelloBrowserApplication.java   |  14 +--
 .../wicket/examples/homepage/HomePage.html      |   3 +-
 wicket-examples/src/main/webapp/WEB-INF/web.xml |  16 +++
 14 files changed, 428 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/Gruntfile.js
----------------------------------------------------------------------
diff --git a/Gruntfile.js b/Gruntfile.js
index cd47c7a..10dbdc3 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -23,7 +23,8 @@ module.exports = function(grunt) {
 			'wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js',
 			"wicket-core/src/main/java/org/apache/wicket/markup/html/form/CheckSelector.js",
 			"wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js",
-			"wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.js"
+			"wicket-core/src/main/java/org/apache/wicket/ajax/form/AjaxFormChoiceComponentUpdatingBehavior.js",
+			"wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js"
 		],
 		extensionsJs = [
 			"wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/form/upload/progressbar.js",

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
new file mode 100644
index 0000000..86b2bb1
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
@@ -0,0 +1,74 @@
+package org.apache.wicket.markup.html.pages;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxCallListener;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
+import org.apache.wicket.core.request.ClientInfo;
+import org.apache.wicket.markup.html.form.Form;
+
+/**
+ * An extension of BrowserInfoForm that uses AjaxFormSubmitBehavior
+ * to collect the client info without redirect to another page
+ */
+public class AjaxBrowserInfoForm extends BrowserInfoForm
+{
+	/**
+	 * Constructor.
+	 *
+	 * @param id component id
+	 */
+	public AjaxBrowserInfoForm(String id)
+	{
+		super(id);
+	}
+
+	@Override
+	protected Form<? extends ClientPropertiesBean> createForm(String componentId)
+	{
+		Form<? extends ClientPropertiesBean> f = super.createForm(componentId);
+		f.add(new AjaxFormSubmitBehavior(f, "domready")
+		{
+			@Override
+			protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+			{
+				super.updateAjaxAttributes(attributes);
+				AjaxCallListener listener = new AjaxCallListener();
+				listener.onBefore(String.format("Wicket.BrowserInfo.populateFields('%s');", getFormMarkupId()));
+				attributes.getAjaxCallListeners().add(listener);
+			}
+
+			@Override
+			protected void onAfterSubmit(AjaxRequestTarget target)
+			{
+				super.onAfterSubmit(target);
+				ClientInfo info = getSession().getClientInfo();
+				AjaxBrowserInfoForm.this.onAfterSubmit(target, info);
+			}
+		});
+		return f;
+	}
+
+	/**
+	 * A callback method called when the client info is collected
+	 *
+	 * @param target
+	 *      The Ajax request handler
+	 * @param info
+	 *      The client info
+	 */
+	protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+	{
+	}
+
+	/**
+	 * Does nothing.
+	 *
+	 * Use {@linkplain #onAfterSubmit(org.apache.wicket.ajax.AjaxRequestTarget, org.apache.wicket.core.request.ClientInfo)}
+	 */
+	@Override
+	protected final void afterSubmit()
+	{
+		super.afterSubmit();
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
index 2e46491..5676493 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.html
@@ -15,39 +15,8 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<!DOCTYPE html>
 <html xmlns:wicket="http://wicket.apache.org">
-	<wicket:head>
-		<script type="text/javascript">/*<![CDATA[*/
-		function submitform() {
-			document.postback.navigatorAppName.value = window.navigator.appName;
-			document.postback.navigatorAppVersion.value = window.navigator.appVersion;
-			document.postback.navigatorAppCodeName.value = window.navigator.appCodeName;
-			var cookieEnabled = (window.navigator.cookieEnabled)? true : false;
-			if (typeof window.navigator.cookieEnabled == "undefined" && !cookieEnabled) { 
-				document.cookie = "wickettestcookie";
-				cookieEnabled = (document.cookie.indexOf("wickettestcookie")!=-1)? true : false;
-			}
-			document.postback.navigatorCookieEnabled.value = cookieEnabled;
-			document.postback.navigatorJavaEnabled.value =  window.navigator.javaEnabled();
-			document.postback.navigatorLanguage.value = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
-			document.postback.navigatorPlatform.value = window.navigator.platform;
-			document.postback.navigatorUserAgent.value = window.navigator.userAgent;
-			if (window.screen) {
-				document.postback.screenWidth.value = window.screen.width;
-				document.postback.screenHeight.value = window.screen.height;
-				document.postback.screenColorDepth.value = window.screen.colorDepth;
-			}
-			document.postback.utcOffset.value = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-			document.postback.utcDSTOffset.value = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-			document.postback.browserWidth.value =  window.innerWidth || document.body.offsetWidth;
-			document.postback.browserHeight.value =  window.innerHeight || document.body.offsetHeight;
-			document.postback.hostname.value =  window.location.hostname;
-
-			document.postback.submit();
-		}
-		/*]]>*/</script>
-	</wicket:head>
 	<wicket:panel>
 		<form name="postback" wicket:id="postback" style="position:absolute; left: -10000px;">
 			<input type="text" wicket:id="navigatorAppName" value="test" />

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
index 0b6d530..653c9eb 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoForm.java
@@ -16,7 +16,8 @@
  */
 package org.apache.wicket.markup.html.pages;
 
-import org.apache.wicket.util.io.IClusterable;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.TextField;
 import org.apache.wicket.markup.html.panel.Panel;
@@ -24,23 +25,24 @@ import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.protocol.http.ClientProperties;
 import org.apache.wicket.protocol.http.WebSession;
 import org.apache.wicket.protocol.http.request.WebClientInfo;
-import org.apache.wicket.core.request.ClientInfo;
 import org.apache.wicket.request.cycle.RequestCycle;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.io.IClusterable;
 
 /**
  * Form for posting JavaScript properties.
  */
 public class BrowserInfoForm extends Panel
 {
-	/** log. */
-	private static final Logger log = LoggerFactory.getLogger(BrowserInfoForm.class);
-
 	private static final long serialVersionUID = 1L;
 
 	/**
-	 * Construct.
+	 * The special form that submits the client/browser info
+	 */
+	private final Form<? extends ClientPropertiesBean> form;
+
+	/**
+	 * Constructor.
 	 * 
 	 * @param id
 	 *            component id
@@ -49,21 +51,32 @@ public class BrowserInfoForm extends Panel
 	{
 		super(id);
 
-		Form<ClientPropertiesBean> form = new Form<ClientPropertiesBean>("postback",
-			new CompoundPropertyModel<ClientPropertiesBean>(new ClientPropertiesBean()))
+		this.form = createForm("postback");
+		form.setOutputMarkupId(true);
+		add(form);
+	}
+
+	/**
+	 * Creates the form
+	 *
+	 * @param componentId
+	 *      the id for the Form component
+	 * @return the Form that will submit the data
+	 */
+	protected Form<? extends ClientPropertiesBean> createForm(String componentId)
+	{
+		Form<ClientPropertiesBean> form = new Form<ClientPropertiesBean>(componentId,
+				new CompoundPropertyModel<ClientPropertiesBean>(new ClientPropertiesBean()))
 		{
 			private static final long serialVersionUID = 1L;
 
-			/**
-			 * @see org.apache.wicket.markup.html.form.Form#onSubmit()
-			 */
 			@Override
 			protected void onSubmit()
 			{
 				ClientPropertiesBean propertiesBean = getModelObject();
 
 				RequestCycle requestCycle = getRequestCycle();
-				WebSession session = (WebSession)getSession();
+				WebSession session = getWebSession();
 				WebClientInfo clientInfo = session.getClientInfo();
 
 				if (clientInfo == null)
@@ -94,27 +107,28 @@ public class BrowserInfoForm extends Panel
 		form.add(new TextField<String>("browserWidth"));
 		form.add(new TextField<String>("browserHeight"));
 		form.add(new TextField<String>("hostname"));
-		add(form);
+		return form;
 	}
 
-
-	/**
-	 * Log a warning that for in order to use this page, you should really be using
-	 * {@link WebClientInfo}.
-	 * 
-	 * @param clientInfo
-	 *            the actual client info object
-	 */
-	void warnNotUsingWebClientInfo(ClientInfo clientInfo)
+	protected void afterSubmit()
 	{
-		log.warn("using " + getClass().getName() + " makes no sense if you are not using " +
-			WebClientInfo.class.getName() + " (you are using " + clientInfo.getClass().getName() +
-			" instead)");
 	}
 
-	protected void afterSubmit()
+	@Override
+	public void renderHead(IHeaderResponse response)
 	{
+		super.renderHead(response);
+
+		response.render(JavaScriptHeaderItem.forReference(
+				new JavaScriptResourceReference(BrowserInfoForm.class, "wicket-browser-info.js")));
+	}
 
+	/**
+	 * @return The markup id of the form that submits the client info
+	 */
+	public String getFormMarkupId()
+	{
+		return form.getMarkupId();
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
index 2427950..81019d4 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.html
@@ -20,7 +20,7 @@
 	<head>
 		<meta wicket:id="meta" http-equiv="refresh" />
 	</head>
-	<body onload="javascript:submitform();">
+	<body>
 		If you see this, it means that both javascript and meta-refresh are not support by
 		your browser configuration. Please click <a wicket:id="link" href="#">this link</a> to
 		continue to the original destination.

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
index 3f5452b..373cbb5 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/BrowserInfoPage.java
@@ -17,6 +17,8 @@
 package org.apache.wicket.markup.html.pages;
 
 import org.apache.wicket.AttributeModifier;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnLoadHeaderItem;
 import org.apache.wicket.markup.html.WebComponent;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.WebPage;
@@ -29,7 +31,6 @@ import org.apache.wicket.protocol.http.request.WebClientInfo;
 import org.apache.wicket.request.cycle.RequestCycle;
 import org.apache.wicket.settings.IRequestCycleSettings;
 
-
 /**
  * <p>
  * This page uses a form post right after the page has loaded in the browser, using JavaScript or
@@ -49,6 +50,8 @@ public class BrowserInfoPage extends WebPage
 {
 	private static final long serialVersionUID = 1L;
 
+	private BrowserInfoForm browserInfoForm;
+
 	/**
 	 * Bookmarkable constructor. This is not for normal framework client use. It will be called
 	 * whenever JavaScript is not supported, and the browser info page's meta refresh fires to this
@@ -74,9 +77,15 @@ public class BrowserInfoPage extends WebPage
 		continueToOriginalDestination();
 	}
 
-	/**
-	 * @see org.apache.wicket.Component#isVersioned()
-	 */
+	@Override
+	public void renderHead(IHeaderResponse response)
+	{
+		super.renderHead(response);
+
+		response.render(OnLoadHeaderItem.forScript(
+				String.format("Wicket.BrowserInfo.submitForm('%s')", browserInfoForm.getFormMarkupId())));
+	}
+
 	@Override
 	public boolean isVersioned()
 	{
@@ -117,18 +126,17 @@ public class BrowserInfoPage extends WebPage
 		WebMarkupContainer link = new WebMarkupContainer("link");
 		link.add(AttributeModifier.replace("href", urlModel));
 		add(link);
-		add(new BrowserInfoForm("postback")
+
+		browserInfoForm = new BrowserInfoForm("postback")
 		{
 			private static final long serialVersionUID = 1L;
 
-			/**
-			 * @see org.apache.wicket.markup.html.pages.BrowserInfoForm#afterSubmit()
-			 */
 			@Override
 			protected void afterSubmit()
 			{
 				continueToOriginalDestination();
 			}
-		});
+		};
+		add(browserInfoForm);
 	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
new file mode 100644
index 0000000..6fb1fa3
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Wicket BrowserInfo Support
+ *
+ * Populates a special form with the client/browser info
+ * and submits it to the server
+ */
+
+;(function (undefined) {
+
+	'use strict';
+
+	if (typeof(Wicket) === 'undefined') {
+		window.Wicket = {};
+	}
+
+	if (typeof(Wicket.BrowserInfo) === 'undefined') {
+		window.Wicket.BrowserInfo = {
+
+			/**
+			 * Populates the form elements with the client info
+			 *
+			 * @param formMarkupId   The markup id of the special form
+			 * @returns {HTMLFormElement} The special form
+			 */
+			populateFields: function(formMarkupId) {
+				var postbackForm = document.getElementById(formMarkupId);
+				postbackForm.navigatorAppName.value = window.navigator.appName;
+				postbackForm.navigatorAppVersion.value = window.navigator.appVersion;
+				postbackForm.navigatorAppCodeName.value = window.navigator.appCodeName;
+				var cookieEnabled = (window.navigator.cookieEnabled);
+				if (typeof(window.navigator.cookieEnabled) === "undefined" && !cookieEnabled) {
+					document.cookie = "wickettestcookie";
+					cookieEnabled = (document.cookie.indexOf("wickettestcookie") !== -1);
+				}
+				postbackForm.navigatorCookieEnabled.value = cookieEnabled;
+				postbackForm.navigatorJavaEnabled.value =  window.navigator.javaEnabled();
+				postbackForm.navigatorLanguage.value = window.navigator.language ? window.navigator.language : window.navigator.userLanguage;
+				postbackForm.navigatorPlatform.value = window.navigator.platform;
+				postbackForm.navigatorUserAgent.value = window.navigator.userAgent;
+				if (window.screen) {
+					postbackForm.screenWidth.value = window.screen.width;
+					postbackForm.screenHeight.value = window.screen.height;
+					postbackForm.screenColorDepth.value = window.screen.colorDepth;
+				}
+				postbackForm.utcOffset.value = (new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				postbackForm.utcDSTOffset.value = (new Date(new Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+				postbackForm.browserWidth.value =  window.innerWidth || document.body.offsetWidth;
+				postbackForm.browserHeight.value =  window.innerHeight || document.body.offsetHeight;
+				postbackForm.hostname.value =  window.location.hostname;
+
+				return postbackForm;
+			},
+
+			/**
+			 * Populates and submits the special form.
+			 *
+			 * @param formMarkupId  The markup id of the special form
+			 */
+			submitForm: function(formMarkupId) {
+				var postbackForm = Wicket.BrowserInfo.populateFields(formMarkupId);
+				postbackForm.submit();
+			}
+		};
+	}
+
+})();

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
new file mode 100644
index 0000000..059abbc
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.html
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+<head>
+    <title>Wicket Examples - hellobrowser</title>
+    <link rel="stylesheet" type="text/css" href="style.css"/>
+</head>
+<body>
+    <div wicket:id="mainNavigation"></div>
+
+    <div wicket:id="form"></div>
+
+	<p>
+	    Hi there. We have been snooping around your browser, even doing a sneaky
+	    redirect to test some javascript properties in the process, and this is what we
+	    found out: <br /><br />
+	    ClientProperties: <span wicket:id="clientinfo">client info here</span>
+	</p>
+
+	<p>
+		<span wicket:id="clienttime">client time info here</span>
+	</p>
+
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
new file mode 100644
index 0000000..824caf0
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/AjaxHelloBrowser.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples.ajaxhellobrowser;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.core.request.ClientInfo;
+import org.apache.wicket.examples.WicketExamplePage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.basic.MultiLineLabel;
+import org.apache.wicket.markup.html.pages.AjaxBrowserInfoForm;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.protocol.http.ClientProperties;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.settings.IRequestCycleSettings;
+
+
+/**
+ * A demo usage of AjaxBrowserInfoForm
+ */
+public class AjaxHelloBrowser extends WicketExamplePage
+{
+	/**
+	 * Constructor.
+	 */
+	public AjaxHelloBrowser()
+	{
+		final MultiLineLabel clientInfo = new MultiLineLabel("clientinfo", new AbstractReadOnlyModel<String>()
+		{
+			@Override
+			public String getObject()
+			{
+				ClientProperties properties = getClientProperties();
+				return properties.toString();
+			}
+		});
+		clientInfo.setOutputMarkupPlaceholderTag(true);
+		clientInfo.setVisible(false);
+
+		IModel<String> clientTimeModel = new AbstractReadOnlyModel<String>()
+		{
+			@Override
+			public String getObject()
+			{
+				ClientProperties properties = getClientProperties();
+				TimeZone timeZone = properties.getTimeZone();
+				if (timeZone != null)
+				{
+					Calendar cal = Calendar.getInstance(timeZone);
+					Locale locale = getLocale();
+					DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, locale);
+					String calAsString = dateFormat.format(cal.getTime());
+					StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
+					b.append(calAsString);
+					b.append(" (and your time zone is ");
+					b.append(timeZone.getDisplayName(getLocale()));
+					b.append(')');
+					return b.toString();
+				}
+				return "Unfortunately, we were not able to figure out what your time zone is, so we have"
+						+ " no idea what your time is";
+			}
+		};
+		final Label clientTime = new Label("clienttime", clientTimeModel);
+		clientTime.setOutputMarkupPlaceholderTag(true);
+		clientTime.setVisible(false);
+
+		AjaxBrowserInfoForm form = new AjaxBrowserInfoForm("form")
+		{
+			@Override
+			protected void onAfterSubmit(AjaxRequestTarget target, ClientInfo info)
+			{
+				super.onAfterSubmit(target, info);
+
+				clientInfo.setVisible(true);
+				clientTime.setVisible(true);
+				target.add(clientInfo, clientTime);
+			}
+		};
+
+		add(form, clientInfo, clientTime);
+	}
+
+	/**
+	 * A helper function that makes sure that gathering of extended browser info
+	 * is not enabled when reading the ClientInfo's properties
+	 *
+	 * @return the currently available client info
+	 */
+	private ClientProperties getClientProperties()
+	{
+		IRequestCycleSettings requestCycleSettings = getApplication().getRequestCycleSettings();
+		boolean gatherExtendedBrowserInfo = requestCycleSettings.getGatherExtendedBrowserInfo();
+		ClientProperties properties = null;
+		try
+		{
+			requestCycleSettings.setGatherExtendedBrowserInfo(false);
+			WebClientInfo clientInfo = (WebClientInfo) getSession().getClientInfo();
+			properties = clientInfo.getProperties();
+		}
+		finally
+		{
+			requestCycleSettings.setGatherExtendedBrowserInfo(gatherExtendedBrowserInfo);
+		}
+		return properties;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
new file mode 100644
index 0000000..982b892
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellobrowser/HelloBrowserApplication.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.examples.ajaxhellobrowser;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.examples.WicketExampleApplication;
+
+/**
+ * Application class for Ajax based browser info extractor.
+ */
+public class HelloBrowserApplication extends WicketExampleApplication
+{
+	@Override
+	public Class<? extends Page> getHomePage()
+	{
+		return AjaxHelloBrowser.class;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
index 5cab415..12532c9 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowser.java
@@ -43,13 +43,8 @@ public class HelloBrowser extends WicketExamplePage
 	 */
 	public HelloBrowser()
 	{
-		// add a label that outputs a the client info object; it will result in
-		// the calls RequestCycle.getClientInfo -> Session.getClientInfo ->
-		// RequestCycle.newClientInfo. this is done once by default and
-		// afterwards cached in the session object. This application uses
-		// a custom requestcycle that overrides newClientInfo to not only
-		// look at the user-agent request header, but also snoops javascript
-		// properties by redirecting to a special page.
+		// Add a label that outputs the client info object; it will result in
+		// the calls Session.getClientInfo.
 
 		// don't use a property model here or anything else that is resolved
 		// during rendering, as changing the request target during rendering
@@ -73,17 +68,17 @@ public class HelloBrowser extends WicketExamplePage
 					Locale locale = getLocale();
 					DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG, locale);
 					String calAsString = dateFormat.format(cal.getTime());
-				 StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
+					StringBuilder b = new StringBuilder("Based on your settings, your time is: ");
 					b.append(calAsString);
 					b.append(" (and your time zone is ");
 					b.append(timeZone.getDisplayName(getLocale()));
-					b.append(")");
+					b.append(')');
 					return b.toString();
 				}
 				return "Unfortunately, we were not able to figure out what your time zone is, so we have"
-					+ "no idea what your time is";
+					+ " no idea what your time is";
 			}
 		};
 		add(new Label("clienttime", clientTimeModel));
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
index 66079cb..4e98f03 100644
--- a/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/hellobrowser/HelloBrowserApplication.java
@@ -26,31 +26,19 @@ import org.apache.wicket.examples.WicketExampleApplication;
  */
 public class HelloBrowserApplication extends WicketExampleApplication
 {
-	/**
-	 * Constructor.
-	 */
-	public HelloBrowserApplication()
-	{
-	}
-
-	/**
-	 * @see org.apache.wicket.Application#getHomePage()
-	 */
 	@Override
 	public Class<? extends Page> getHomePage()
 	{
 		return HelloBrowser.class;
 	}
 
-	/**
-	 * @see org.apache.wicket.examples.WicketExampleApplication#init()
-	 */
 	@Override
 	protected void init()
 	{
 		super.init();
 
 		getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
+
 		mountPage("howdy", HelloBrowser.class);
 	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
index e8d396d..e6c5daf 100644
--- a/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
+++ b/wicket-examples/src/main/resources/org/apache/wicket/examples/homepage/HomePage.html
@@ -41,7 +41,8 @@
         <tr><td align="right"><a href="template">template</a></td><td> - Templating example.</td></tr>
         <tr><td align="right"><a href="mailtemplate">mail template</a></td><td> - Generate mail templates out of Page, Panel or TextTemplate.</td></tr>
 		<tr><td align="right"><a href="stateless">stateless</a></td><td> - Demonstrates stateless pages/sessions.</td></tr>
-        <tr><td align="right"><a href="hellobrowser">hellobrowser</a></td><td> - Browser snooper.</td></tr>
+        <tr><td align="right"><a href="hellobrowser">Browser Info</a></td><td> - Extracts client info by redirecting to a temporary page.</td></tr>
+        <tr><td align="right"><a href="ajaxhellobrowser">Ajax Browser Info</a></td><td> - Extracts client info by using Ajax.</td></tr>
         <tr><td align="right"><a href="frames">frames</a></td><td> - Example demonstrating HTML frames.</td></tr>
         <tr><td align="right"><a href="prototype">ajax with prototype</a></td><td> - AJAX example using prototype.js.</td></tr>
         <tr><td align="right"><a href="wizard">abacadabra</a></td><td> - Demonstrates the wizard component.</td></tr>

http://git-wip-us.apache.org/repos/asf/wicket/blob/90235c1c/wicket-examples/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index 38799f0..db9c840 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -117,6 +117,15 @@
 	</filter>
 
 	<filter>
+		<filter-name>AjaxHelloBrowserApplication</filter-name>
+		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+		<init-param>
+			<param-name>applicationClassName</param-name>
+			<param-value>org.apache.wicket.examples.ajaxhellobrowser.HelloBrowserApplication</param-value>
+		</init-param>
+	</filter>
+
+	<filter>
 		<filter-name>StockQuoteApplication</filter-name>
 		<filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
 		<init-param>
@@ -572,6 +581,13 @@
 	</filter-mapping>
 
 	<filter-mapping>
+		<filter-name>AjaxHelloBrowserApplication</filter-name>
+		<url-pattern>/ajaxhellobrowser/*</url-pattern>
+		<dispatcher>REQUEST</dispatcher>
+		<dispatcher>INCLUDE</dispatcher>
+	</filter-mapping>
+
+	<filter-mapping>
 		<filter-name>FormInputApplication</filter-name>
 		<url-pattern>/forminput/*</url-pattern>
 		<dispatcher>REQUEST</dispatcher>


[2/2] git commit: Add licence

Posted by mg...@apache.org.
Add licence


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/7fcbfe7b
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/7fcbfe7b
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/7fcbfe7b

Branch: refs/heads/5435-ajax-browser-info
Commit: 7fcbfe7bc4172c8671ab037c73780c1006d1704d
Parents: 90235c1
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Thu Dec 12 15:55:15 2013 +0200
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Thu Dec 12 15:55:15 2013 +0200

----------------------------------------------------------------------
 .../markup/html/pages/AjaxBrowserInfoForm.java      | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/7fcbfe7b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
index 86b2bb1..00cdcca 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/AjaxBrowserInfoForm.java
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.wicket.markup.html.pages;
 
 import org.apache.wicket.ajax.AjaxRequestTarget;