You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "reiern70 (via GitHub)" <gi...@apache.org> on 2023/04/17 04:55:56 UTC
[GitHub] [wicket] reiern70 opened a new pull request, #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
reiern70 opened a new pull request, #580:
URL: https://github.com/apache/wicket/pull/580
AjaxClientInfoBehavior is AJAX timer based. This seems not to work reliable in all situations. We add a AjaxOnDomReadyClientInfoBehavior that uses DOMREADY and seems to work more reliable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] martin-g commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "martin-g (via GitHub)" <gi...@apache.org>.
martin-g commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1170876606
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
Review Comment:
no need of this implicit constructor
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
+ {
+ super();
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target)
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+
+ IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
+ WebClientInfo clientInfo = newWebClientInfo(requestCycle);
+ clientInfo.getProperties().read(requestParameters);
+ Session.get().setClientInfo(clientInfo);
+
+ onClientInfo(target, clientInfo);
+ }
+
+ protected WebClientInfo newWebClientInfo(RequestCycle requestCycle)
+ {
+ return new WebClientInfo(requestCycle);
+ }
+
+ /**
+ * A callback method invoked when the client info is collected.
+ *
+ * @param target
+ * The Ajax request handler
+ * @param clientInfo
+ * The collected info for the client
+ */
+ protected void onClientInfo(AjaxRequestTarget target, WebClientInfo clientInfo)
+ {
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+ {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(AjaxRequestAttributes.Method.POST);
Review Comment:
Let's be explicit here and call `attributes.setEventNames("domready")`.
Currently it depends on an implementation [detail](https://github.com/apache/wicket/blob/8e33df5dae79d3ba7dbf4ffa2115ddf6b51518eb/wicket-core/src/main/java/org/apache/wicket/ajax/res/js/wicket-ajax-jquery.js#L1666).
##########
wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js:
##########
@@ -96,7 +96,6 @@
return postbackForm;
},
-
Review Comment:
unnecessary
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1168487506
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
+ {
+ super();
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target)
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+
+ IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
+ WebClientInfo clientInfo = newWebClientInfo(requestCycle);
+ clientInfo.getProperties().read(requestParameters);
+ Session.get().setClientInfo(clientInfo);
+
+ onClientInfo(target, clientInfo);
+ }
+
+ protected WebClientInfo newWebClientInfo(RequestCycle requestCycle)
+ {
+ return new WebClientInfo(requestCycle);
+ }
+
+ /**
+ * A callback method invoked when the client info is collected.
+ *
+ * @param target
+ * The Ajax request handler
+ * @param clientInfo
+ * The collected info for the client
+ */
+ protected void onClientInfo(AjaxRequestTarget target, WebClientInfo clientInfo)
+ {
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+ {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(AjaxRequestAttributes.Method.POST);
+ attributes.getDynamicExtraParameters().add("return Wicket.BrowserInfo.collect()");
+ }
+
+ @Override
+ public void renderHead(Component component, IHeaderResponse response)
+ {
+ super.renderHead(component, response);
+
+ response.render(JavaScriptHeaderItem.forReference(BrowserInfoForm.JS));
+ response.render(OnDomReadyHeaderItem.forScript(getCallbackScript()));
Review Comment:
@theigl
This causes behavior be called from client side
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] theigl commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1168218100
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.settings.RequestCycleSettings;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
+ {
+ super();
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target)
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+
+ IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
+ WebClientInfo clientInfo = newWebClientInfo(requestCycle);
+ clientInfo.getProperties().read(requestParameters);
+ Session.get().setClientInfo(clientInfo);
+
+ onClientInfo(target, clientInfo);
+ }
+
+ protected WebClientInfo newWebClientInfo(RequestCycle requestCycle)
+ {
+ return new WebClientInfo(requestCycle);
+ }
+
+ /**
+ * A callback method invoked when the client info is collected.
+ *
+ * @param target
+ * The Ajax request handler
+ * @param clientInfo
+ * The collected info for the client
+ */
+ protected void onClientInfo(AjaxRequestTarget target, WebClientInfo clientInfo)
+ {
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+ {
+ super.updateAjaxAttributes(attributes);
+
+ attributes.getDynamicExtraParameters().add("return Wicket.BrowserInfo.collect()");
Review Comment:
I think this can be removed since you call `Wicket.BrowserInfo.collect()` in the new `postBack` method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on PR #580:
URL: https://github.com/apache/wicket/pull/580#issuecomment-1511089121
@theigl Many thanks for your review. I got rid of JavaScript special code and now all id determined at java side,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1170885932
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
Review Comment:
True. Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 merged pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 merged PR #580:
URL: https://github.com/apache/wicket/pull/580
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on PR #580:
URL: https://github.com/apache/wicket/pull/580#issuecomment-1514185250
@martin-g This is just a version of AjaxClientInfoBehavior that uses dom ready.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1170885311
##########
wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js:
##########
@@ -96,7 +96,6 @@
return postbackForm;
},
-
Review Comment:
true. FIxed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] theigl commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "theigl (via GitHub)" <gi...@apache.org>.
theigl commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1168220796
##########
wicket-examples/src/main/java/org/apache/wicket/examples/ajaxhellowbrowserondomready/AjaxHelloBrowserOnDomReady.html:
##########
@@ -0,0 +1,19 @@
+<?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>
+</head>
+<body>
+ <wicket:extend>
+ <p>
+ This page uses <em>org.apache.wicket.ajax.AjaxClientInfoBehavior</em>
Review Comment:
Should be `AjaxOnDomReadyClientInfoBehavior`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [wicket] reiern70 commented on a diff in pull request #580: [WICKET-7048] add AjaxOnDomReadyClientInfoBehavior
Posted by "reiern70 (via GitHub)" <gi...@apache.org>.
reiern70 commented on code in PR #580:
URL: https://github.com/apache/wicket/pull/580#discussion_r1168235328
##########
wicket-core/src/main/java/org/apache/wicket/ajax/AjaxOnDomReadyClientInfoBehavior.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.ajax;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.Session;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.pages.BrowserInfoForm;
+import org.apache.wicket.protocol.http.request.WebClientInfo;
+import org.apache.wicket.request.IRequestParameters;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.settings.RequestCycleSettings;
+import org.apache.wicket.util.lang.Args;
+import org.danekja.java.util.function.serializable.SerializableBiConsumer;
+
+/**
+ * A behavior that collects the information to populate
+ * WebClientInfo's ClientProperties by using Ajax. Compared to
+ * {@link AjaxClientInfoBehavior} this class does not use a timer
+ * but the DOM ready "event" to collect browser info.
+ *
+ * @see #onClientInfo(AjaxRequestTarget, WebClientInfo)
+ */
+public class AjaxOnDomReadyClientInfoBehavior extends AbstractDefaultAjaxBehavior
+{
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor.
+ *
+ */
+ public AjaxOnDomReadyClientInfoBehavior()
+ {
+ super();
+ }
+
+ @Override
+ protected void respond(AjaxRequestTarget target)
+ {
+ RequestCycle requestCycle = RequestCycle.get();
+
+ IRequestParameters requestParameters = requestCycle.getRequest().getRequestParameters();
+ WebClientInfo clientInfo = newWebClientInfo(requestCycle);
+ clientInfo.getProperties().read(requestParameters);
+ Session.get().setClientInfo(clientInfo);
+
+ onClientInfo(target, clientInfo);
+ }
+
+ protected WebClientInfo newWebClientInfo(RequestCycle requestCycle)
+ {
+ return new WebClientInfo(requestCycle);
+ }
+
+ /**
+ * A callback method invoked when the client info is collected.
+ *
+ * @param target
+ * The Ajax request handler
+ * @param clientInfo
+ * The collected info for the client
+ */
+ protected void onClientInfo(AjaxRequestTarget target, WebClientInfo clientInfo)
+ {
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
+ {
+ super.updateAjaxAttributes(attributes);
+
+ attributes.getDynamicExtraParameters().add("return Wicket.BrowserInfo.collect()");
Review Comment:
True... Or the JavaScriot code can be removed. Checking!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@wicket.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org