From b84937b1a555929ac18b28a2f4632e2c9bb94caa Mon Sep 17 00:00:00 2001 From: rkurucz Date: Tue, 10 Oct 2023 10:25:29 +0200 Subject: [PATCH] WICKET-7078 CSP: inline JS in Choices and Selection of Palette --- .../html/form/palette/component/Choices.java | 14 ++++++-------- .../html/form/palette/component/Selection.java | 13 ++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Choices.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Choices.java index ad8b5936f41..29b1316816a 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Choices.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Choices.java @@ -19,8 +19,8 @@ import java.util.Iterator; import org.apache.wicket.extensions.markup.html.form.palette.Palette; -import org.apache.wicket.markup.ComponentTag; -import org.apache.wicket.util.value.IValueMap; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.OnEventHeaderItem; /** @@ -44,19 +44,17 @@ public Choices(final String id, final Palette palette) super(id, palette); } - @Override - protected void onComponentTag(final ComponentTag tag) + public void renderHead(IHeaderResponse response) { - super.onComponentTag(tag); - IValueMap attrs = tag.getAttributes(); + super.renderHead(response); String onFocus = getPalette().getChoicesOnFocusJS(); if (onFocus != null) { - attrs.put("onfocus", onFocus); + response.render(OnEventHeaderItem.forComponent(this, "focus", onFocus)); } - tag.getAttributes().put("ondblclick", getPalette().getAddOnClickJS()); + response.render(OnEventHeaderItem.forComponent(this, "dblclick", getPalette().getAddOnClickJS())); } @Override diff --git a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Selection.java b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Selection.java index 68561ff1e93..096ba7d15a4 100644 --- a/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Selection.java +++ b/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/form/palette/component/Selection.java @@ -19,8 +19,8 @@ import java.util.Iterator; import org.apache.wicket.extensions.markup.html.form.palette.Palette; -import org.apache.wicket.markup.ComponentTag; -import org.apache.wicket.util.value.IValueMap; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.OnEventHeaderItem; /** @@ -45,18 +45,17 @@ public Selection(final String id, final Palette palette) } @Override - protected void onComponentTag(final ComponentTag tag) + public void renderHead(IHeaderResponse response) { - super.onComponentTag(tag); - IValueMap attrs = tag.getAttributes(); + super.renderHead(response); String onFocus = getPalette().getSelectionOnFocusJS(); if (onFocus != null) { - attrs.put("onfocus", onFocus); + response.render(OnEventHeaderItem.forComponent(this, "focus", onFocus)); } - tag.getAttributes().put("ondblclick", getPalette().getRemoveOnClickJS()); + response.render(OnEventHeaderItem.forComponent(this, "dblclick", getPalette().getRemoveOnClickJS())); } @Override