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/09/26 07:17:11 UTC

[isis] branch master updated: ISIS-3219: fix: attach model if not yet attached

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 50d578b557 ISIS-3219: fix: attach model if not yet attached
50d578b557 is described below

commit 50d578b55793258323a3781d7a841f9b87f566e7
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 26 09:17:06 2022 +0200

    ISIS-3219: fix: attach model if not yet attached
---
 .../interaction/prop/PropertyInteractionWkt.java   | 49 +++++++++++++---------
 1 file changed, 30 insertions(+), 19 deletions(-)

diff --git a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/interaction/prop/PropertyInteractionWkt.java b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/interaction/prop/PropertyInteractionWkt.java
index ac0c57b293..c4eb904eec 100644
--- a/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/interaction/prop/PropertyInteractionWkt.java
+++ b/viewers/wicket/model/src/main/java/org/apache/isis/viewer/wicket/model/models/interaction/prop/PropertyInteractionWkt.java
@@ -26,6 +26,7 @@ import org.apache.wicket.model.ChainingModel;
 import org.apache.isis.applib.annotation.Where;
 import org.apache.isis.commons.collections.Can;
 import org.apache.isis.commons.internal.assertions._Assert;
+import org.apache.isis.commons.internal.base._Blackhole;
 import org.apache.isis.commons.internal.base._Lazy;
 import org.apache.isis.commons.internal.exceptions._Exceptions;
 import org.apache.isis.core.metamodel.interactions.managed.ManagedProperty;
@@ -73,23 +74,8 @@ extends HasBookmarkedOwnerAbstract<PropertyInteraction> {
 
     @Override
     protected PropertyInteraction load() {
-
-        // restore the lazy field - don't evaluate yet
-        propertyNegotiationModel =
-                _Lazy.threadSafe(()->{
-                    val propIa = propertyInteraction();
-                    val prop = propIa.getManagedProperty().orElseThrow();
-                    ManagedObjects.refreshViewmodel(prop.getOwner(), /* bookmark provider*/ null);
-                    return propIa.startPropertyNegotiation()
-                            //.orElseThrow(()->_Exceptions.noSuchElement(memberId))
-                            ;
-                });
-
-        return PropertyInteraction.wrap(
-                ManagedProperty.lookupProperty(getBookmarkedOwner(), memberId, where)
-                .orElseThrow(()->_Exceptions.noSuchElement("property '%s' in %s",
-                        memberId,
-                        getBookmarkedOwner().getSpecification())));
+        setupLazyPropertyNegotiationModel();
+        return loadPropertyInteraction();
     }
 
     @Override
@@ -116,14 +102,39 @@ extends HasBookmarkedOwnerAbstract<PropertyInteraction> {
     private transient _Lazy<Optional<PropertyNegotiationModel>> propertyNegotiationModel;
 
     public final PropertyNegotiationModel propertyNegotiationModel() {
+        if(this.isAttached()) {
+            return propertyNegotiationModel.get()
+                    .orElseThrow(()->_Exceptions.noSuchElement(memberId));
+        }
+
+        _Blackhole.consume(getObject()); // re-attach
         _Assert.assertTrue(this.isAttached(), "model is not attached");
-        return propertyNegotiationModel.get()
-                .orElseThrow(()->_Exceptions.noSuchElement(memberId));
+        return propertyNegotiationModel();
     }
 
     public void resetPropertyToDefault() {
         propertyNegotiationModel.clear();
     }
 
+    private void setupLazyPropertyNegotiationModel() {
+        // restore the lazy field - don't evaluate yet
+        propertyNegotiationModel =
+                _Lazy.threadSafe(()->{
+                    val propIa = propertyInteraction();
+                    val prop = propIa.getManagedProperty().orElseThrow();
+                    ManagedObjects.refreshViewmodel(prop.getOwner(), /* bookmark provider*/ null);
+                    return propIa.startPropertyNegotiation()
+                            //.orElseThrow(()->_Exceptions.noSuchElement(memberId))
+                            ;
+                });
+    }
+
+    private PropertyInteraction loadPropertyInteraction() {
+        return PropertyInteraction.wrap(
+            ManagedProperty.lookupProperty(getBookmarkedOwner(), memberId, where)
+            .orElseThrow(()->_Exceptions.noSuchElement("property '%s' in %s",
+                    memberId,
+                    getBookmarkedOwner().getSpecification())));
+    }
 
 }