You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2020/06/14 07:24:34 UTC

[isis] 01/01: ISIS-2222: fleshes out demo app with stateful view model.

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

danhaywood pushed a commit to branch ISIS-2222
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 4a6615dd09780782eaf38218cd90c37b62c31007
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Jun 14 08:24:07 2020 +0100

    ISIS-2222: fleshes out demo app with stateful view model.
---
 .../dom/_infra/MarkupVariableResolverService.java  |  2 +-
 .../dom/homepage/DemoHomePage-description.adoc     |  4 +-
 .../demoapp/dom/homepage/DemoHomePage-welcome.adoc | 12 +++--
 .../demoapp/dom/homepage/DemoHomePage.layout.xml   |  6 +--
 .../StatefulViewModelUsingJaxb-description.adoc    | 38 +++++++++++++++
 .../dom/viewmodels/StatefulViewModelUsingJaxb.java | 53 ++++++++++++++++++++
 .../StatefulViewModelUsingJaxb.layout.xml}         | 13 ++---
 .../java/demoapp/dom/viewmodels/ViewModels.java    | 56 ++++++++++++++++++++++
 .../main/java/demoapp/webapp/menubars.layout.xml   | 17 ++++---
 .../demo/domain/src/main/resources/application.yml |  4 +-
 10 files changed, 179 insertions(+), 26 deletions(-)

diff --git a/examples/demo/domain/src/main/java/demoapp/dom/_infra/MarkupVariableResolverService.java b/examples/demo/domain/src/main/java/demoapp/dom/_infra/MarkupVariableResolverService.java
index 108b0ea..3303aec 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/_infra/MarkupVariableResolverService.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/_infra/MarkupVariableResolverService.java
@@ -20,7 +20,7 @@ public class MarkupVariableResolverService {
         "SOURCES_ISIS", "https://github.com/apache/isis/blob/master/core/applib/src/main/java",
         "SOURCES_DEMO", "https://github.com/apache/isis/tree/master/examples/demo/domain/src/main/java",
         "ISSUES_DEMO", "https://issues.apache.org/jira/",
-        "ISIS_WEBSITE", "https://isis.apache.org/docs/2.0.0-M3/"
+        "ISIS_VERSION", "2.0.0-M3"
     );
 
     /**
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-description.adoc
index c4052fa..d08f1ac 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-description.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-description.adoc
@@ -1,4 +1,4 @@
-Apache Isis applications can nominate a view model to act as the home page, using the link:https://isis.apache.org/refguide/2.0.0-M3/applib-ant/HomePage.html[`@HomePage`] annotation:
+Apache Isis applications can nominate a view model to act as the home page, using the link:https://isis.apache.org/refguide/${ISIS_VERSION}/applib-ant/HomePage.html[`@HomePage`] annotation:
 
 [source,java]
 ----
@@ -27,5 +27,5 @@ This application's home page is pretty simple, not much more than a couple of ha
 A more common implementation of a home page is as a dashboard, displaying the most useful current information to the user (perhaps a task list, or alerts).
 Such a home page would have a number of repository services injected into it, in order to query and render those tasks or alerts.
 
-It would probably also have the framework's link:https://isis.apache.org/refguide/2.0.0-M3/applib-svc/UserService.html[`UserService`] injected, in order that the information displayed is relevant to the current user.
+It would probably also have the framework's link:https://isis.apache.org/refguide/${ISIS_VERSION}/applib-svc/UserService.html[`UserService`] injected, in order that the information displayed is relevant to the current user.
 As you can see, this app's home page does actually do this, in order to "personalise" the title.
\ No newline at end of file
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
index 5ce34f2..ac30e4f 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
+++ b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage-welcome.adoc
@@ -1,8 +1,10 @@
-This link:https://isis.apache.org[Apache Isis] application demonstrates the programming model for the various features provided by the framework.
+This is an link:https://isis.apache.org[Apache Isis] application to demonstrate the programming model for the various features provided by the framework.
 
 On the left hand side of each web page you'll find the feature, and on the right hand side you'll find an explanation of the feature with code examples.
 
-Since this is the home page, this is probably a good place to explain the page layout:
+== Page Layout
+
+This is probably as good place as any to explain the page layout of an Apache Isis webapp:
 
 * At the top is the menu bar.
 +
@@ -22,7 +24,7 @@ Click into the application and try things out.
 
 NOTE: The demo app uses an in-memory database, so any changes made will be lost when the app is stopped.
 
-=== Getting Help and Assistance
+== Getting Help and Assistance
 
-There is plenty of documentation on our link:${ISIS_WEBSITE}about.html[website].
-Also subscribe to our link:${ISIS_WEBSITE}support/mailing-list.html[mailing list] or join our link:${ISIS_WEBSITE}support/slack-channel.html[Slack channel].
\ No newline at end of file
+There is plenty of documentation on our link:https://isis.apache.org/docs/${ISIS_VERSION}/about.html[website].
+Also subscribe to our link:https://isis.apache.org/docs/${ISIS_VERSION}/support/mailing-list.html[mailing list] or join our link:https://isis.apache.org/docs/${ISIS_VERSION}/support/slack-channel.html[Slack channel].
\ No newline at end of file
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml
index b64d137..55d68c2 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml
@@ -18,13 +18,13 @@
 	</bs3:row>
 	<bs3:row>
         <bs3:col span="6">
-            <cpt:fieldSet name="" id="general" unreferencedProperties="true">
+            <cpt:fieldSet name="" id="general">
                 <cpt:property id="welcome" labelPosition="NONE"/>
             </cpt:fieldSet>
+			<cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/>
         </bs3:col>
 		<bs3:col span="6">
-			<cpt:fieldSet name="" id="description" />
-			<cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/>
+			<cpt:fieldSet name="Description" id="description" />
 		</bs3:col>
 		<bs3:col span="6" unreferencedCollections="true">
 		</bs3:col>
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb-description.adoc b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb-description.adoc
new file mode 100644
index 0000000..2ba6a2b
--- /dev/null
+++ b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb-description.adoc
@@ -0,0 +1,38 @@
+End users interact with link:https://isis.apache.org/userguide/${ISIS_VERSION}/fun/overview.html#view-models[view models] in the same as a domain entity.
+
+However, whereas domain entities are mapped to a datastore, view models are not.
+Instead they are recreated dynamically by serializing their state, typically into the URL itself.
+
+The framework provides a number of ways to serialize this state, but the most flexible and standard is to use JAXB annotations:
+
+[source,java]
+----
+@XmlRootElement(name = "demoapp.DemoStatefulViewModel")     // <.>
+@XmlType                                                    // <.>
+@XmlAccessorType(XmlAccessType.FIELD)                       // <.>
+@DomainObject(
+        nature=Nature.VIEW_MODEL
+        , objectType = "demoapp.DemoStatefulViewModel"
+)
+public class StatefulViewModelUsingJaxb implements HasAsciiDocDescription {
+
+    // ...
+
+    @Property(editing = Editing.ENABLED)
+    @Getter @Setter
+    private String message;                                 // <.>
+}
+----
+
+<.> mandatory, specifies this is a JAXB element
+<.> mandatory boilerplate
+<.> serializes the state by reading the field
+<.> no further JAXB annotations required for the property.
+
+Notice how the 'message' property can be modified and survives a refresh of the page.
+
+Behind the scenes, the object is converted into an XML serialization, and that is URL encoded.
+
+As you can see this can result in long URLs.
+If the URL is too long, or needs to be encrypted, then the link:https://isis.apache.org/refguide/${ISIS_VERSION}/applib-svc/UrlEncodingService.html[`UrlEncodingService`] SPI can provide for different serializations.
+
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.java b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.java
new file mode 100644
index 0000000..de6976e
--- /dev/null
+++ b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.java
@@ -0,0 +1,53 @@
+/*
+ *  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.viewmodels;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Editing;
+import org.apache.isis.applib.annotation.Nature;
+import org.apache.isis.applib.annotation.Property;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import demoapp.dom._infra.HasAsciiDocDescription;
+
+@XmlRootElement(name = "demoapp.DemoStatefulViewModel")
+@XmlType
+@XmlAccessorType(XmlAccessType.FIELD)
+@DomainObject(
+        nature=Nature.VIEW_MODEL
+        , objectType = "demoapp.DemoStatefulViewModel"
+)
+public class StatefulViewModelUsingJaxb implements HasAsciiDocDescription {
+
+    public String title() {
+        return getMessage();
+    }
+
+    @Property(editing = Editing.ENABLED)
+    @Getter @Setter
+    private String message;
+
+}
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.layout.xml
similarity index 77%
copy from examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml
copy to examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.layout.xml
index b64d137..7e6e8bf 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/homepage/DemoHomePage.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/StatefulViewModelUsingJaxb.layout.xml
@@ -18,15 +18,16 @@
 	</bs3:row>
 	<bs3:row>
         <bs3:col span="6">
-            <cpt:fieldSet name="" id="general" unreferencedProperties="true">
-                <cpt:property id="welcome" labelPosition="NONE"/>
+            <cpt:fieldSet name="General" id="general">
+                <cpt:property id="message" labelPosition="TOP"/>
             </cpt:fieldSet>
+			<cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/>
         </bs3:col>
 		<bs3:col span="6">
-			<cpt:fieldSet name="" id="description" />
-			<cpt:fieldSet name="Other" id="other" unreferencedProperties="true"/>
-		</bs3:col>
-		<bs3:col span="6" unreferencedCollections="true">
+			<cpt:fieldSet name="Description" id="description" />
 		</bs3:col>
 	</bs3:row>
+	<bs3:row>
+		<bs3:col span="12" unreferencedCollections="true"/>
+	</bs3:row>
 </bs3:grid>
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/ViewModels.java b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/ViewModels.java
new file mode 100644
index 0000000..ea82948
--- /dev/null
+++ b/examples/demo/domain/src/main/java/demoapp/dom/viewmodels/ViewModels.java
@@ -0,0 +1,56 @@
+/*
+ *  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.viewmodels;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.Editing;
+import org.apache.isis.applib.annotation.Nature;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Property;
+import org.apache.isis.applib.annotation.SemanticsOf;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.val;
+
+import demoapp.dom._infra.HasAsciiDocDescription;
+
+@DomainService(
+        objectType = "demoapp.ViewModels"
+)
+public class ViewModels {
+
+    @Action(semantics = SemanticsOf.SAFE)
+    public StatefulViewModelUsingJaxb openStateful(final String message) {
+        val viewModel = new StatefulViewModelUsingJaxb();
+        viewModel.setMessage(message);
+        return viewModel;
+    }
+    public String default0OpenStateful() {
+        return "Some initial state";
+    }
+
+}
diff --git a/examples/demo/domain/src/main/java/demoapp/webapp/menubars.layout.xml b/examples/demo/domain/src/main/java/demoapp/webapp/menubars.layout.xml
index 7b5e8eb..e84845d 100644
--- a/examples/demo/domain/src/main/java/demoapp/webapp/menubars.layout.xml
+++ b/examples/demo/domain/src/main/java/demoapp/webapp/menubars.layout.xml
@@ -33,20 +33,23 @@
         </mb3:menu>
         
         <mb3:menu>
-            <mb3:named>Tooltips</mb3:named>
+            <mb3:named>View Models</mb3:named>
             <mb3:section>
-                <mb3:serviceAction objectType="demo.TooltipMenu" id="tooltipDemo">
-                    <cpt:named>Tooltip Demo</cpt:named>
-                </mb3:serviceAction>
+                <mb3:serviceAction objectType="demoapp.ViewModels" id="openStateful"/>
             </mb3:section>
         </mb3:menu>
         
         <mb3:menu>
+            <mb3:named>Tooltips</mb3:named>
+            <mb3:section>
+                <mb3:serviceAction objectType="demo.TooltipMenu" id="tooltipDemo"/>
+            </mb3:section>
+        </mb3:menu>
+
+        <mb3:menu>
             <mb3:named>Trees</mb3:named>
             <mb3:section>
-                <mb3:serviceAction objectType="demo.TreeDemoMenu" id="fileSystemTree">
-                    <cpt:named>File System Tree</cpt:named>
-                </mb3:serviceAction>
+                <mb3:serviceAction objectType="demo.TreeDemoMenu" id="fileSystemTree"/>
             </mb3:section>
         </mb3:menu>
         
diff --git a/examples/demo/domain/src/main/resources/application.yml b/examples/demo/domain/src/main/resources/application.yml
index 3f53c74..279a9be 100644
--- a/examples/demo/domain/src/main/resources/application.yml
+++ b/examples/demo/domain/src/main/resources/application.yml
@@ -80,8 +80,8 @@ isis:
       development-utilities:
         enable: false
       bookmarked-pages:
-        show-chooser: false
-        show-drop-down-on-footer: false
+        show-chooser: true
+        show-drop-down-on-footer: true
       dialog-mode: sidebar
       dialog-mode-for-menu: modal