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 2021/02/22 12:23:51 UTC
[isis] branch master updated: ISIS-1264: No-arg actions returning
Blob/Clob but whose return type is simply java.lang.Object no longer
require AjaxDeferredBehaviour
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 fe048cb ISIS-1264: No-arg actions returning Blob/Clob but whose return type is simply java.lang.Object no longer require AjaxDeferredBehaviour
fe048cb is described below
commit fe048cbdfd336842829117709ecf75de975d6e04
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Feb 22 13:23:35 2021 +0100
ISIS-1264: No-arg actions returning Blob/Clob but whose return type is
simply java.lang.Object no longer require AjaxDeferredBehaviour
---
.../apache/isis/applib/value/OpenUrlStrategy.java | 2 +-
.../widgets/linkandlabel/ActionLink.java | 25 ++------
.../linkandlabel/AjaxDeferredBehaviour.java | 72 +++++-----------------
3 files changed, 23 insertions(+), 76 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/value/OpenUrlStrategy.java b/api/applib/src/main/java/org/apache/isis/applib/value/OpenUrlStrategy.java
index 0cb680b..dd848a5 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/value/OpenUrlStrategy.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/value/OpenUrlStrategy.java
@@ -20,7 +20,7 @@ package org.apache.isis.applib.value;
/**
* Controls, for Action results of type {@link LocalResourcePath}, whether the redirect URL
- * should open in the same or a new window/tap.
+ * should open in the same or a new window/tab.
*
* @since 2.0 {@index}
* @see LocalResourcePath
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java
index 52e675b..89ca475 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/ActionLink.java
@@ -72,11 +72,8 @@ public abstract class ActionLink extends AjaxLink<ManagedObject> implements IAja
// trivial optimization; also store the objectAction if it is available (saves looking it up)
objectAction = model.getMetaModel();
- // this returns non-null if the action is no-arg and returns a URL or a Blob or a Clob.
+ // this returns non-null if the action is no-arg and returns a LocalResourcePath or URL.
// Otherwise can use default handling
- // TODO: the method looks at the actual compile-time return type;
- // TODO: cannot see a way to check at runtime what is returned.
- // TODO: see https://issues.apache.org/jira/browse/ISIS-1264 for further detail.
ajaxDeferredBehaviourIfAny = determineDeferredBehaviour();
if(ajaxDeferredBehaviourIfAny != null) {
this.add(ajaxDeferredBehaviourIfAny);
@@ -93,7 +90,8 @@ public abstract class ActionLink extends AjaxLink<ManagedObject> implements IAja
_Probe.entryPoint(EntryPoint.USER_INTERACTION, "Wicket Ajax Request, "
+ "originating from User clicking an Action Link.");
- if (ajaxDeferredBehaviourIfAny != null) {
+ if(ajaxDeferredBehaviourIfAny!=null
+ && ajaxDeferredBehaviourIfAny.needsDeferring()) {
ajaxDeferredBehaviourIfAny.initiate(target);
return;
}
@@ -183,6 +181,7 @@ public abstract class ActionLink extends AjaxLink<ManagedObject> implements IAja
return ((WicketViewerSettingsAccessor) Application.get()).getSettings();
}
+ // TODO: should unify with ActionResultResponseType (as used in ActionParametersPanel)
AjaxDeferredBehaviour determineDeferredBehaviour() {
val action = getObjectAction();
@@ -193,20 +192,8 @@ public abstract class ActionLink extends AjaxLink<ManagedObject> implements IAja
return null; // default behavior, don't defer
}
- val actionModel = this.getActionModel();
- val actionReturnType = actionReturnTypeSpec.getCorrespondingClass();
-
- // TODO: should unify with ActionResultResponseType (as used in ActionParametersPanel)
- if (actionReturnType == java.net.URL.class
- || actionReturnType == LocalResourcePath.class) {
- return AjaxDeferredBehaviour.redirecting(this.getActionModel());
- }
- if ((actionReturnType == org.apache.isis.applib.value.Blob.class
- || actionReturnType == org.apache.isis.applib.value.Clob.class)) {
- return AjaxDeferredBehaviour.downloading(actionModel);
- }
-
- return null; // default behavior, don't defer
+ // use redirect handler, which only executes if needed
+ return AjaxDeferredBehaviour.redirecting(this.getActionModel());
}
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/AjaxDeferredBehaviour.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/AjaxDeferredBehaviour.java
index 8172ec2..4b68007 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/AjaxDeferredBehaviour.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/linkandlabel/AjaxDeferredBehaviour.java
@@ -23,13 +23,10 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractAjaxBehavior;
import org.apache.wicket.request.IRequestHandler;
import org.apache.wicket.request.Url;
-import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
-import org.apache.wicket.util.time.Duration;
import org.apache.isis.applib.value.LocalResourcePath;
import org.apache.isis.core.metamodel.spec.ManagedObject;
import org.apache.isis.core.metamodel.spec.ManagedObjects;
-import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
import org.apache.isis.viewer.wicket.model.models.ActionModel;
import org.apache.isis.viewer.wicket.ui.actionresponse.ActionResultResponseHandlingStrategy;
@@ -44,8 +41,9 @@ public abstract class AjaxDeferredBehaviour extends AbstractAjaxBehavior {
private final @NonNull ActionModel actionModel;
// -- FACTORIES
-
+
public static AjaxDeferredBehaviour redirecting(final @NonNull ActionModel actionModel){
+
/**
* adapted from:
*
@@ -54,19 +52,28 @@ public abstract class AjaxDeferredBehaviour extends AbstractAjaxBehavior {
return new AjaxDeferredBehaviour(actionModel) {
private static final long serialVersionUID = 1L;
+
+ @Override
+ public boolean needsDeferring() {
+ // introspect the action result, to decide whether needs deferring
+ val value = getResultValue();
+ if(value==null) {
+ return false;
+ }
+ return value instanceof LocalResourcePath
+ || value instanceof java.net.URL;
+ }
+
@Override
protected String javascriptFor(String url) {
// introspect the action result, to decide which JS to use
-
val value = getResultValue();
-
if(value instanceof LocalResourcePath) {
if(((LocalResourcePath)value).getOpenUrlStrategy().isSameWindow()) {
return javascriptFor_sameWindow(this, url);
}
}
-
return javascriptFor_newWindow(this, url);
}
@@ -80,37 +87,6 @@ public abstract class AjaxDeferredBehaviour extends AbstractAjaxBehavior {
};
}
- public static AjaxDeferredBehaviour downloading(final @NonNull ActionModel actionModel){
- /**
- * adapted from:
- *
- * @see https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
- */
- return new AjaxDeferredBehaviour(actionModel) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected String javascriptFor(String url) {
- return javascriptFor_sameWindow(this, url);
- }
-
- @Override
- protected IRequestHandler getRequestHandler() {
- val value = getResultValue();
- freeResultValue();
-
- val handler = ActionModel.downloadHandler(value);
-
- //ISIS-1619, prevent clients from caching the response content
- return isIdempotentOrCachable(actionModel)
- ? handler
- : enforceNoCacheOnClientSide(handler);
- }
-
- };
- }
-
// -- IMPL
/**
@@ -133,7 +109,8 @@ public abstract class AjaxDeferredBehaviour extends AbstractAjaxBehavior {
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
}
-
+
+ public abstract boolean needsDeferring();
protected abstract IRequestHandler getRequestHandler();
protected abstract String javascriptFor(String url);
@@ -165,23 +142,6 @@ public abstract class AjaxDeferredBehaviour extends AbstractAjaxBehavior {
private static String javascriptFor_sameWindow(AjaxDeferredBehaviour deferredBehaviour, String url) {
return "\"window.location.href='" + url + "'\"";
}
-
- private static boolean isIdempotentOrCachable(ActionModel actionModel) {
- val objectAction = actionModel.getMetaModel();
- return ObjectAction.Util.isIdempotentOrCachable(objectAction);
- }
-
- // -- CLIENT SIDE CACHING ASPECTS ...
-
- private static IRequestHandler enforceNoCacheOnClientSide(IRequestHandler downloadHandler){
- if(downloadHandler==null)
- return downloadHandler;
- if(downloadHandler instanceof ResourceStreamRequestHandler)
- ((ResourceStreamRequestHandler) downloadHandler)
- .setCacheDuration(Duration.seconds(0));
-
- return downloadHandler;
- }
}