[
https://issues.apache.org/jira/browse/WICKET-7048?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17712913#comment-17712913
]
ASF GitHub Bot commented on WICKET-7048:
----------------------------------------
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!
> add an AjaxExtendedClientInfoBehavior that makes use of OnDomReady
> ------------------------------------------------------------------
>
> Key: WICKET-7048
> URL: https://issues.apache.org/jira/browse/WICKET-7048
> Project: Wicket
> Issue Type: Improvement
> Reporter: Ernesto Reinaldo Barreiro
> Priority: Major
> Attachments: image-2023-04-17-07-18-56-191.png
>
>
> We have noticed that AjaxClientInfoBehavior only provides a limeted set of
> cleint side properties and that
> RequestCycleSettings#getGatherExtendedBrowserInfo()=true is requiered to
> gather things like client time zone. This uses a redicrect to some special
> page and this causes some problem to us. We provide an AJAX behavior that
> gathers same info as RequestCycleSettings#getGatherExtendedBrowserInfo().
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)