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

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


The following commit(s) were added to refs/heads/master by this push:
     new e9688fbbb3 CAUSEWAY-2485: reworks @ActionLayout#redirectPolicy
e9688fbbb3 is described below

commit e9688fbbb33af9eaaedaa3bc03644239d1261057
Author: danhaywood <[email protected]>
AuthorDate: Mon Apr 17 21:22:25 2023 +0100

    CAUSEWAY-2485: reworks @ActionLayout#redirectPolicy
---
 ...ActionLayoutRedirectPolicyPage-description.adoc | 55 ++++++++++++++++++----
 .../ActionLayoutRedirectPolicyPage.java            | 55 ++++++++++++++--------
 .../ActionLayoutRedirectPolicyPage.layout.xml      | 27 ++++-------
 ...rectPolicyPage_incrementRedirectEvenIfSame.java | 45 ++++++++++++++++++
 ...tPolicyPage_incrementRedirectOnlyIfDiffers.java | 45 ++++++++++++++++++
 .../src/main/resources/static/css/application.css  |  6 +++
 6 files changed, 187 insertions(+), 46 deletions(-)

diff --git 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage-description.adoc
 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage-description.adoc
index 55390cb99a..44e66bd90f 100644
--- 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage-description.adoc
+++ 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage-description.adoc
@@ -1,20 +1,59 @@
 :Notice: Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with this work 
for additional information regarding copyright ownership. The ASF licenses this 
file to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance with the License. You may obtain a copy of 
the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by 
applicable law or ag [...]
 
-If an action returns its target, then the `redirectPolicy` attribute determines
-whether to update the page or instead to redirect (forcing a re-rendering of a 
new page).
+[WARNING]
+====
+This feature is currently *not* supported by the _Wicket Viewer_; see 
link:https://issues.apache.org/jira/browse/CAUSEWAY-1659[CAUSEWAY-1659]
+====
 
+If an action returns its target, then the 
link:https://causeway.apache.org/refguide/2.0.0-SNAPSHOT/applib/index/annotation/ActionLayout.html#redirectpolicy[@ActionLayout#redirectPolicy]`
 attribute determines
+whether to update the page or instead to redirect (forcing a re-rendering of a 
new page).
 Not re-rendering can provide a smoother UI experience.
 
-[WARNING]
-====
-This feature is currently *not* supported by the _Wicket Viewer_ 
https://issues.apache.org/jira/browse/CAUSEWAY-1659
 
-(Perhaps a feasible showcase could be to render a local time property, then 
demonstrate that its UI would not update after action invocation.)
+=== How this demo works
+
+This page has a `count` property with two associated actions.
+These both increment the `count`, but use different redirect policies.
+
+The page also has a `currentTime` property, that displays the current time.
+This is a derived property that also has a built-in delay of 1 second.
+
+[source,java,indent=0]
+----
+include::ActionLayoutRedirectPolicyPage.java[tags=class]
+----
+<.> for demonstration purposes, this UI component opts out of being redrawn if 
there is no redirect.
+
+[NOTE]
 ====
+In this demo we are somewhat misusing the `@PropertyLayout#repainting` 
element; normally this is used for components that are expensive to render 
_and_ which are generally unchanging.
+The most common example of such a property would be a PDF, rendered using the 
link:https://causeway.apache.org/vw/2.0.0-RC1/pdfjs/about.html[PDF.js] 
extension (the 
link:https://causeway.apache.org/refguide/2.0.0-RC1/extensions/index/pdfjs/applib/annotations/PdfJsViewer.html#section-top[@PdfJsViewer]
 annotation).
+====
+
+The behaviour observed therefore depends on which action is used:
 
+* if the "increment even if same" action is called:
++
 [source,java,indent=0]
 ----
-include::ActionLayoutRedirectPolicyPage.java[tags=act]
+include::ActionLayoutRedirectPolicyPage_incrementRedirectEvenIfSame.java[tags=class]
 ----
+<.> always render the page.
++
+This causes the entire page to be re-rendered.
+That means that the current time will be updated, but only after a 1 second 
delay
 
-<.> this action returns its target, and so setting `ONLY_IF_DIFFERS` instructs 
the _viewer_ to not re-render the current page
+* if the "increment redirect only if differs" action is called:
++
+[source,java,indent=0]
+----
+include::ActionLayoutRedirectPolicyPage_incrementRedirectOnlyIfDiffers.java[tags=class]
+----
+<.> only re-render the updated property.
++
+This _should_ cause only the updated property to re-render.
++
+[WARNING]
+====
+Because this feature is currently *not* supported by the _Wicket Viewer_, in 
fact the `currentTime` property also re-renders; see 
link:https://issues.apache.org/jira/browse/CAUSEWAY-1659[CAUSEWAY-1659]
+====
diff --git 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.java
 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.java
index eb4c0eb840..c60fb4c4c9 100644
--- 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.java
+++ 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.java
@@ -18,10 +18,13 @@
  */
 package demoapp.dom.domain.actions.ActionLayout.redirectPolicy;
 
+import javax.inject.Inject;
 import javax.inject.Named;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.causeway.applib.annotation.Action;
@@ -29,41 +32,53 @@ import org.apache.causeway.applib.annotation.ActionLayout;
 import org.apache.causeway.applib.annotation.DomainObject;
 import org.apache.causeway.applib.annotation.Nature;
 import org.apache.causeway.applib.annotation.ObjectSupport;
+import org.apache.causeway.applib.annotation.Optionality;
+import org.apache.causeway.applib.annotation.Property;
+import org.apache.causeway.applib.annotation.PropertyLayout;
 import org.apache.causeway.applib.annotation.Redirect;
+import org.apache.causeway.applib.annotation.Repainting;
+import org.apache.causeway.applib.services.clock.ClockService;
 
 import demoapp.dom._infra.asciidocdesc.HasAsciiDocDescription;
 
-//tag::class[]
-@DomainObject(
-        nature=Nature.VIEW_MODEL)
-@Named("demo.ActionLayoutRedirectPolicyVm")
+import lombok.Getter;
+import lombok.Setter;
+import lombok.SneakyThrows;
+
+@DomainObject(nature=Nature.VIEW_MODEL)
+@Named("demo.ActionLayoutRedirectPolicyPage")
 @XmlRootElement(name = "root")
 @XmlType
 @XmlAccessorType(XmlAccessType.FIELD)
-//tag::act[]
+//tag::class[]
+// ...
 public class ActionLayoutRedirectPolicyPage
-//end::act[]
+//end::class[]
 implements HasAsciiDocDescription
-//tag::act[]
+//tag::class[]
 {
-//end::act[]
+    @Property(optionality = Optionality.OPTIONAL)
+    @XmlElement(required = false)
+    @Getter @Setter
+    private Integer count;
+
+    @SneakyThrows
+    @Property
+    @PropertyLayout(repainting = Repainting.NO_REPAINT) // <.>
+    public String getCurrentTime() {
+        Thread.sleep(1000);
+        return clockService.getClock().nowAsLocalDateTime().toString();
+    }
+
+    // ...
+//end::class[]
 
     @ObjectSupport public String title() {
         return "@ActionLayout#redirectPolicy";
     }
 
-//tag::act[]
-    @Action
-    @ActionLayout(
-            redirectPolicy = Redirect.ONLY_IF_DIFFERS // <.>
-//end::act[]
-            ,describedAs = "@ActionLayout(redirectPolicy = 
Redirect.ONLY_IF_DIFFERS)"
-//tag::act[]
-            )
-    public ActionLayoutRedirectPolicyPage act(final String arg) {
-        return this;
-    }
+//tag::class[]
 
+    @Inject @XmlTransient private ClockService clockService;
 }
-//end::act[]
 //end::class[]
diff --git 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.layout.xml
 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.layout.xml
index b7b4ab6651..eefcc3123f 100644
--- 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.layout.xml
+++ 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage.layout.xml
@@ -26,24 +26,15 @@
 
        <bs3:row>
                <bs3:col span="6">
-                       <cpt:fieldSet name="General" id="general"/>
-                       <cpt:fieldSet name="Annotated" id="annotated"/>
-                       <cpt:fieldSet name="Layout" id="layout">
-                               <cpt:action id="layoutPanel" position="PANEL">
-                                       <cpt:named>Positioned on 
panel</cpt:named>
-                               </cpt:action>
-                               <cpt:action id="layoutPanelDropDown" 
position="PANEL_DROPDOWN">
-                                       <cpt:named>Positioned on panel in drop 
down</cpt:named>
-                               </cpt:action>
-                               <cpt:property id="readOnlyProperty2">
-                                       <cpt:action id="layoutBelow" 
position="BELOW">
-                                               <cpt:named>Positioned 
below</cpt:named>
-                                       </cpt:action>
-                                       <cpt:action id="layoutRight" 
position="RIGHT">
-                                               <cpt:named>Positioned 
right</cpt:named>
-                                       </cpt:action>
-                               </cpt:property>
-                       </cpt:fieldSet>
+                       <cpt:fieldSet name="General" id="general">
+                <cpt:property id="count">
+                    <cpt:action id="incrementRedirectEvenIfSame"/>
+                    <cpt:action id="incrementRedirectOnlyIfDiffers"/>
+                </cpt:property>
+            </cpt:fieldSet>
+                       <cpt:fieldSet name="Time" id="time">
+                <cpt:property id="currentTime"/>
+            </cpt:fieldSet>
                        <cpt:fieldSet name="Other" id="other" 
unreferencedProperties="true"/>
                </bs3:col>
                <bs3:col span="6">
diff --git 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectEvenIfSame.java
 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectEvenIfSame.java
new file mode 100644
index 0000000000..8c131b8286
--- /dev/null
+++ 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectEvenIfSame.java
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package demoapp.dom.domain.actions.ActionLayout.redirectPolicy;
+
+import lombok.RequiredArgsConstructor;
+
+import org.apache.causeway.applib.annotation.*;
+
+
+//tag::class[]
+@Action(semantics = SemanticsOf.IDEMPOTENT)
+@ActionLayout(
+        redirectPolicy = Redirect.EVEN_IF_SAME      // <.>
+)
+@RequiredArgsConstructor
+public class ActionLayoutRedirectPolicyPage_incrementRedirectEvenIfSame {
+    // ...
+//end::class[]
+    private final ActionLayoutRedirectPolicyPage page;
+
+    @MemberSupport public ActionLayoutRedirectPolicyPage act() {
+        Integer count = page.getCount();
+        page.setCount(count == null ? 1 : count + 1);
+        return page;
+    }
+
+//tag::class[]
+}
+//end::class[]
diff --git 
a/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectOnlyIfDiffers.java
 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectOnlyIfDiffers.java
new file mode 100644
index 0000000000..a4c4e92058
--- /dev/null
+++ 
b/examples/demo/domain/src/main/java/demoapp/dom/domain/actions/ActionLayout/redirectPolicy/ActionLayoutRedirectPolicyPage_incrementRedirectOnlyIfDiffers.java
@@ -0,0 +1,45 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package demoapp.dom.domain.actions.ActionLayout.redirectPolicy;
+
+import lombok.RequiredArgsConstructor;
+
+import org.apache.causeway.applib.annotation.*;
+
+
+//tag::class[]
+@Action(semantics = SemanticsOf.IDEMPOTENT)
+@ActionLayout(
+        redirectPolicy = Redirect.ONLY_IF_DIFFERS       // <.>
+)
+@RequiredArgsConstructor
+public class ActionLayoutRedirectPolicyPage_incrementRedirectOnlyIfDiffers {
+    // ...
+//end::class[]
+    private final ActionLayoutRedirectPolicyPage page;
+
+    @MemberSupport public ActionLayoutRedirectPolicyPage act() {
+        Integer count = page.getCount();
+        page.setCount(count == null ? 1 : count + 1);
+        return page;
+    }
+
+//tag::class[]
+}
+//end::class[]
diff --git a/examples/demo/domain/src/main/resources/static/css/application.css 
b/examples/demo/domain/src/main/resources/static/css/application.css
index f4e1da3bad..e7ca19bb21 100644
--- a/examples/demo/domain/src/main/resources/static/css/application.css
+++ b/examples/demo/domain/src/main/resources/static/css/application.css
@@ -318,3 +318,9 @@ tr.odd.custom2 > td,
 .line-through {
     text-decoration: line-through;
 }
+
+.navbar-nav.primary ul.dropdown-menu,
+.navbar-nav.secondary ul.dropdown-menu,
+.navbar-nav.tertiary ul.dropdown-menu {
+    max-height: 800px;
+}

Reply via email to