wicket-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From papega...@apache.org
Subject [wicket] branch csp updated: WICKET-6739: moved js from onclick to event bindings
Date Wed, 05 Feb 2020 19:57:52 GMT
This is an automated email from the ASF dual-hosted git repository.

papegaaij pushed a commit to branch csp
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/csp by this push:
     new 7954c78  WICKET-6739: moved js from onclick to event bindings
7954c78 is described below

commit 7954c78d4d26f9926f67a9bee63fe9033b9a664c
Author: Emond Papegaaij <emond.papegaaij@topicus.nl>
AuthorDate: Wed Feb 5 20:57:33 2020 +0100

    WICKET-6739: moved js from onclick to event bindings
---
 .../markup/html/form/palette/Palette.java          | 43 +++++++++++++---------
 .../form/palette/component/AbstractOptions.java    | 24 ++++++------
 2 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
index b26f42c..cfe47be 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/Palette.java
@@ -30,6 +30,7 @@ import org.apache.wicket.extensions.markup.html.form.palette.theme.DefaultTheme;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.head.IHeaderResponse;
 import org.apache.wicket.markup.head.JavaScriptHeaderItem;
+import org.apache.wicket.markup.head.OnEventHeaderItem;
 import org.apache.wicket.markup.html.WebMarkupContainer;
 import org.apache.wicket.markup.html.basic.Label;
 import org.apache.wicket.markup.html.form.FormComponent;
@@ -312,10 +313,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(final ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getDownOnClickJS());
+				super.renderHead(response);
+				response.render(
+					OnEventHeaderItem.forComponent(this, "click", Palette.this.getDownOnClickJS()));
 			}
 		};
 	}
@@ -332,10 +334,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(final ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getUpOnClickJS());
+				super.renderHead(response);
+				response.render(
+					OnEventHeaderItem.forComponent(this, "click", Palette.this.getUpOnClickJS()));
 			}
 		};
 	}
@@ -352,10 +355,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(final ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getRemoveOnClickJS());
+				super.renderHead(response);
+				response.render(OnEventHeaderItem.forComponent(this, "click",
+					Palette.this.getRemoveOnClickJS()));
 			}
 		};
 	}
@@ -372,10 +376,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(final ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getAddOnClickJS());
+				super.renderHead(response);
+				response.render(
+					OnEventHeaderItem.forComponent(this, "click", Palette.this.getAddOnClickJS()));
 			}
 		};
 	}
@@ -417,10 +422,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getAddAllOnClickJS());
+				super.renderHead(response);
+				response.render(OnEventHeaderItem.forComponent(this, "click",
+					Palette.this.getAddAllOnClickJS()));
 			}
 		};
 	}
@@ -438,10 +444,11 @@ public class Palette<T> extends FormComponentPanel<Collection<T>>
 			private static final long serialVersionUID = 1L;
 
 			@Override
-			protected void onComponentTag(ComponentTag tag)
+			public void renderHead(IHeaderResponse response)
 			{
-				super.onComponentTag(tag);
-				tag.getAttributes().put("onclick", Palette.this.getRemoveAllOnClickJS());
+				super.renderHead(response);
+				response.render(OnEventHeaderItem.forComponent(this, "click",
+					Palette.this.getRemoveAllOnClickJS()));
 			}
 		};
 	}
diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
index 9c276fd..65e70e9 100644
--- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
+++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/AbstractOptions.java
@@ -19,10 +19,11 @@ package org.apache.wicket.extensions.markup.html.form.palette.component;
 import java.util.Iterator;
 import java.util.Map;
 
-import org.apache.wicket.core.util.string.JavaScriptUtils;
 import org.apache.wicket.extensions.markup.html.form.palette.Palette;
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
 import org.apache.wicket.markup.html.form.FormComponent;
 import org.apache.wicket.markup.html.form.IChoiceRenderer;
 import org.apache.wicket.util.convert.IConverter;
@@ -176,22 +177,19 @@ public abstract class AbstractOptions<T> extends FormComponent<T>
 		{
 			attrs.put("disabled", "disabled");
 		}
-
-		avoidAjaxSerialization();
 	}
 
-	/**
-	 * A piece of javascript to avoid serializing the options during AJAX serialization.
-	 */
-	protected void avoidAjaxSerialization()
+	@Override
+	public void renderHead(IHeaderResponse response)
 	{
-		getResponse().write(
-			JavaScriptUtils.SCRIPT_OPEN_TAG +
-				"if (typeof(Wicket) != \"undefined\" && typeof(Wicket.Form) != \"undefined\")"
+
-				"    Wicket.Form.excludeFromAjaxSerialization." + getMarkupId() + "='true';" +
-				JavaScriptUtils.SCRIPT_CLOSE_TAG);
-	}
+		super.renderHead(response);
 
+		// A piece of javascript to avoid serializing the options during AJAX serialization.
+		response.render(OnDomReadyHeaderItem.forScript(
+			"if (typeof(Wicket) != \"undefined\" && typeof(Wicket.Form) != \"undefined\")"
+				+ "    Wicket.Form.excludeFromAjaxSerialization." + getMarkupId() + "='true';"));
+	}
+	
 	/**
 	 * {@inheritDoc}
 	 */


Mime
View raw message