From 307e407623348dc6eaadfd60f46c620902c7f82f Mon Sep 17 00:00:00 2001 From: nmandrescu <17854915+nmandrescu@users.noreply.github.com> Date: Fri, 4 Jun 2021 21:34:11 +0300 Subject: [PATCH] Resolves #361 (DG Toolkit side) --- .../toolkit/forms/wicket/FormsWebApplication.java | 8 ++++++++ .../components/form/BootstrapDeleteButton.java | 10 +++++++--- .../form/DateTimeFieldBootstrapFormComponent.java | 10 +++++----- .../FileInputBootstrapFormComponentWrapper.html | 6 +++--- .../form/PercentageFieldBootstrapFormComponent.html | 13 ++++++------- .../components/form/ToolkitSummernoteEditor.java | 7 ++++--- .../components/table/AjaxBootstrapNavigator.html | 4 ++-- .../page/edit/AbstractEditStatusEntityPage.html | 2 +- .../forms/wicket/page/edit/EditTestFormPage.html | 4 ++++ .../forms/wicket/page/edit/EditTestFormPage.java | 5 +++++ .../wicket/page/edit/EditTestFormPage.properties | 1 + .../forms/wicket/page/lists/AbstractListPage.html | 2 +- .../toolkit/persistence/dao/TestForm.java | 11 +++++++++++ 13 files changed, 58 insertions(+), 25 deletions(-) diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/FormsWebApplication.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/FormsWebApplication.java index 97984957..6bfc147d 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/FormsWebApplication.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/FormsWebApplication.java @@ -31,6 +31,7 @@ import org.apache.wicket.ajax.AjaxNewWindowNotifyingBehavior; import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication; import org.apache.wicket.authroles.authentication.AuthenticatedWebSession; +import org.apache.wicket.csp.CSPDirective; import org.apache.wicket.markup.head.filter.JavaScriptFilteredIntoFooterHeaderResponse; import org.apache.wicket.markup.html.IPackageResourceGuard; import org.apache.wicket.markup.html.SecurePackageResourceGuard; @@ -240,6 +241,13 @@ protected void init() { // TODO make Wicket usage CSP compliant (temporarily disabled) // https://ci.apache.org/projects/wicket/guide/9.x/single.html#_content_security_policy_csp getCspSettings().blocking().disabled(); + /* + // wicket-bootstrap-extension has to be CSP compliant to enable it + getCspSettings().blocking() + .strict() + // whitelist images rendered via data: + .add(CSPDirective.IMG_SRC, "data:"); + */ } /** diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/BootstrapDeleteButton.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/BootstrapDeleteButton.java index 56b708cd..77884f3c 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/BootstrapDeleteButton.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/BootstrapDeleteButton.java @@ -20,10 +20,10 @@ import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.attributes.AjaxCallListener; import org.apache.wicket.ajax.attributes.AjaxRequestAttributes; -import org.apache.wicket.behavior.AttributeAppender; import org.apache.wicket.event.IEvent; +import org.apache.wicket.markup.head.IHeaderResponse; +import org.apache.wicket.markup.head.OnEventHeaderItem; import org.apache.wicket.model.IModel; -import org.apache.wicket.model.Model; import org.devgateway.toolkit.forms.wicket.components.ComponentUtil; import org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent; @@ -53,7 +53,6 @@ public BootstrapDeleteButton(final String id) { @Override protected void onInitialize() { super.onInitialize(); - add(new AttributeAppender("onclick", new Model("window.onbeforeunload = null;"), " ")); setDefaultFormProcessing(false); setIconType(FontAwesome5IconType.trash_s); @@ -62,6 +61,11 @@ protected void onInitialize() { } } + public void renderHead(IHeaderResponse response) { + super.renderHead(response); + response.render(OnEventHeaderItem.forComponent(this, "onclick", "window.onbeforeunload = null;")); + } + @Override public void onEvent(final IEvent event) { if (event.getPayload() instanceof EditingDisabledEvent) { diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DateTimeFieldBootstrapFormComponent.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DateTimeFieldBootstrapFormComponent.java index c43ead8a..e243800e 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DateTimeFieldBootstrapFormComponent.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/DateTimeFieldBootstrapFormComponent.java @@ -10,13 +10,13 @@ * Development Gateway - initial API and implementation *******************************************************************************/ /** - * + * */ package org.devgateway.toolkit.forms.wicket.components.form; +import de.agilecoders.wicket.core.markup.html.bootstrap.behavior.CssClassNameAppender; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.datetime.DatetimePicker; import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.datetime.DatetimePickerConfig; -import org.apache.wicket.AttributeModifier; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxLink; import org.apache.wicket.model.IModel; @@ -25,7 +25,7 @@ /** * @author mpostelnicu - * + * */ public class DateTimeFieldBootstrapFormComponent extends GenericBootstrapFormComponent { private static final long serialVersionUID = 6829640010904041758L; @@ -69,7 +69,7 @@ public String getUpdateEvent() { /* * (non-Javadoc) - * + * * @see org.devgateway.toolkit.forms.wicket.components.form. * GenericBootstrapFormComponent#onConfigure() */ @@ -77,7 +77,7 @@ public String getUpdateEvent() { protected void onInitialize() { super.onInitialize(); - border.add(new AttributeModifier("style", "position:relative;")); + border.add(new CssClassNameAppender("position-relative")); IndicatingAjaxLink clearDateLink = new IndicatingAjaxLink("clearDate") { private static final long serialVersionUID = -1705495886974891511L; diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/FileInputBootstrapFormComponentWrapper.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/FileInputBootstrapFormComponentWrapper.html index a6e94872..a28adbc1 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/FileInputBootstrapFormComponentWrapper.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/FileInputBootstrapFormComponentWrapper.html @@ -16,8 +16,8 @@ - - + + @@ -39,7 +39,7 @@ - + diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/PercentageFieldBootstrapFormComponent.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/PercentageFieldBootstrapFormComponent.html index 9b85a66f..37cf96ff 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/PercentageFieldBootstrapFormComponent.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/PercentageFieldBootstrapFormComponent.html @@ -3,16 +3,15 @@ xmlns:wicket="http://wicket.apache.org"> -
- - +
+ + + +
- \ No newline at end of file + diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/ToolkitSummernoteEditor.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/ToolkitSummernoteEditor.java index e2e72f71..b698041d 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/ToolkitSummernoteEditor.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/form/ToolkitSummernoteEditor.java @@ -2,6 +2,7 @@ import com.google.common.io.BaseEncoding; import de.agilecoders.wicket.core.markup.html.bootstrap.form.InputBehavior; +import de.agilecoders.wicket.core.util.Attributes; import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteConfig; import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteEditorCssReference; import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteEditorFormDataReference; @@ -9,7 +10,7 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteEditorOverlayCssReference; import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteStorage; import de.agilecoders.wicket.extensions.markup.html.bootstrap.editor.SummernoteStoredImageResourceReference; -import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesomeCssReference; +import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesome5CssReference; import de.agilecoders.wicket.extensions.markup.html.bootstrap.references.SpinJsReference; import de.agilecoders.wicket.jquery.IKey; import org.apache.commons.fileupload.FileItem; @@ -108,7 +109,7 @@ public ToolkitSummernoteEditor(final String id, final IModel model, fina @Override protected void onComponentTag(final ComponentTag tag) { if (!isEnabledInHierarchy()) { - tag.put("style", "display:none;"); + Attributes.addClass(tag, "d-none"); if (tag.isOpenClose()) { // always transform the tag to
so even labels defined as render tag.setType(XmlTag.TagType.OPEN); @@ -159,7 +160,7 @@ public void renderHead(final IHeaderResponse response) { return; } response.render(CssHeaderItem.forReference(SummernoteEditorCssReference.instance())); - response.render(CssHeaderItem.forReference(FontAwesomeCssReference.instance())); + response.render(CssHeaderItem.forReference(FontAwesome5CssReference.instance())); response.render(CssHeaderItem.forReference(SummernoteEditorOverlayCssReference.instance())); response.render(JavaScriptHeaderItem.forReference(SummernoteEditorJavaScriptReference.instance())); response.render(JavaScriptHeaderItem.forReference(SummernoteEditorFormDataReference.instance())); diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/table/AjaxBootstrapNavigator.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/table/AjaxBootstrapNavigator.html index 262ef2aa..00e11fc9 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/table/AjaxBootstrapNavigator.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/table/AjaxBootstrapNavigator.html @@ -2,7 +2,7 @@ -
+
  • «« @@ -23,4 +23,4 @@
- \ No newline at end of file + diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.html index efa99fb7..4fd9f44b 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.html @@ -78,7 +78,7 @@ - + diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.html index 8afe057c..e15f2ba8 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.html @@ -39,6 +39,10 @@
+
+
+
+
diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.java index 5052d4a7..9b207aff 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.java @@ -31,6 +31,7 @@ import org.devgateway.toolkit.forms.wicket.components.form.DateFieldBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.DateTimeFieldBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.FileInputBootstrapFormComponent; +import org.devgateway.toolkit.forms.wicket.components.form.PercentageFieldBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.Select2ChoiceBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.Select2MultiChoiceBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.SummernoteBootstrapFormComponent; @@ -136,6 +137,10 @@ protected void onInitialize() { dateTime.required(); editForm.add(dateTime); + PercentageFieldBootstrapFormComponent percentage = new PercentageFieldBootstrapFormComponent("percentage"); + percentage.required(); + editForm.add(percentage); + FileInputBootstrapFormComponent fileInput = new FileInputBootstrapFormComponent("fileInput"); fileInput.required(); editForm.add(fileInput); diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.properties b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.properties index f762a4e6..0695aad5 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.properties +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/EditTestFormPage.properties @@ -20,6 +20,7 @@ checkboxPicker.label=Checkbox Picker checkboxToggle.label=Checkbox Toggle date.label=Date dateTime.label=Datetime +percentage.label=Percentage fileInput.label=File Input summernote.label=Summernote Editor colorPicker.label=Color Picker diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/lists/AbstractListPage.html b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/lists/AbstractListPage.html index e7a4e9e0..9e098692 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/lists/AbstractListPage.html +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/lists/AbstractListPage.html @@ -16,7 +16,7 @@
- +