Skip to content

Commit

Permalink
WICKET-7078 CSP: inline JS in Choices and Selection of Palette
Browse files Browse the repository at this point in the history
  • Loading branch information
rkurucz authored and bitstorm committed Oct 11, 2023
1 parent 3d0c2ee commit b84937b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -44,19 +44,17 @@ public Choices(final String id, final Palette<T> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -45,18 +45,17 @@ public Selection(final String id, final Palette<T> 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
Expand Down

0 comments on commit b84937b

Please sign in to comment.