You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/06/08 08:08:28 UTC

[isis] branch master updated: ISIS-3070: hacky hotfix for validation happening too early

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 8d2cf10d9c ISIS-3070: hacky hotfix for validation happening too early
8d2cf10d9c is described below

commit 8d2cf10d9c4851919276054f2a36a59bd8255910
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jun 8 10:08:20 2022 +0200

    ISIS-3070: hacky hotfix for validation happening too early
---
 .../scalars/reference/EntityLinkSelect2Panel.java  | 31 ++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/EntityLinkSelect2Panel.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/EntityLinkSelect2Panel.java
index 1efe358523..41b0a7c411 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/EntityLinkSelect2Panel.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/reference/EntityLinkSelect2Panel.java
@@ -18,9 +18,11 @@
  */
 package org.apache.isis.viewer.wicket.ui.components.scalars.reference;
 
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
 import org.apache.wicket.markup.html.form.FormComponentPanel;
 import org.wicketstuff.select2.Select2MultiChoice;
 
+import org.apache.isis.commons.internal.exceptions._Exceptions;
 import org.apache.isis.core.metamodel.spec.ManagedObject;
 import org.apache.isis.viewer.wicket.ui.components.widgets.formcomponent.CancelHintRequired;
 import org.apache.isis.viewer.wicket.ui.components.widgets.formcomponent.FormComponentPanelAbstract;
@@ -31,15 +33,21 @@ implements CancelHintRequired  {
 
     private static final long serialVersionUID = 1L;
 
-    ReferencePanel owningPanel;
+    private ReferencePanel owningPanel;
 
     public EntityLinkSelect2Panel(final String id, final ReferencePanel owningPanel) {
         super(id, owningPanel.scalarModel());
         this.owningPanel = owningPanel;
-
         setType(ManagedObject.class);
     }
 
+    @Override
+    public void validate() {
+        if(shouldValidate()) {
+            super.validate();
+        }
+    }
+
     /**
      * Necessary because {@link FormComponentPanel} overrides this as <tt>true</tt>, whereas we want to
      * report on the state of the underlying {@link org.wicketstuff.select2.Select2Choice} or
@@ -69,4 +77,23 @@ implements CancelHintRequired  {
         // no-op
     }
 
+    // -- HELPER
+
+    /**
+     * [ISIS-3070]
+     * Skip validation if one of the callers is an {@link AjaxFormComponentUpdatingBehavior},
+     * as this validation might be called too early,
+     * when the pending value is not yet updated to the user's (new) input.
+     * Instead wait for the AjaxFormComponentUpdatingBehavior, which happens later,
+     * when the actual pending value is available for validation.
+     * <p>
+     * This is a hack, for the lack of a better solution yet.
+     */
+    private boolean shouldValidate() {
+        return !_Exceptions
+        .streamStackTrace()
+        .anyMatch(element->
+                    element.getClassName().contains(AjaxFormComponentUpdatingBehavior.class.getSimpleName()));
+    }
+
 }