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

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

commit 6adc5edc98a489521d40f24a8ecf8bd014900398
Author: Dan Haywood <d...@haywood-associates.co.uk>
AuthorDate: Fri Feb 23 16:52:32 2018 +0000

    ISIS-1874: adds guard against NPE, and ensures choices facet not installed 
on incompatible parameters
---
 ...onParameterDefaultsAndChoicesPostProcessor.java | 56 ++++++++++++++--------
 .../ui/components/collection/CollectionPanel.java  |  7 +--
 2 files changed, 41 insertions(+), 22 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
index 56c34e8..97b6c0f 100644
--- 
a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
+++ 
b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/postprocessors/param/ActionCollectionParameterDefaultsAndChoicesPostProcessor.java
@@ -82,6 +82,9 @@ public class 
ActionCollectionParameterDefaultsAndChoicesPostProcessor implements
             final ObjectActionParameter.Predicates.CollectionParameter 
whetherCollectionParamOfType =
                     new 
ObjectActionParameter.Predicates.CollectionParameter(specification);
 
+            final ObjectActionParameter.Predicates.ScalarParameter 
whetherScalarParamOfType =
+                    new 
ObjectActionParameter.Predicates.ScalarParameter(specification);
+
             final ImmutableList<ObjectAction> actions = 
FluentIterable.from(objectActions)
                     .filter(ObjectAction.Predicates.associatedWith(otma))
                     .toList();
@@ -90,12 +93,16 @@ public class 
ActionCollectionParameterDefaultsAndChoicesPostProcessor implements
 
                 final List<ObjectActionParameter> parameters = 
action.getParameters();
 
+                final ImmutableList<ObjectActionParameter> 
compatibleCollectionParams = FluentIterable.from(parameters)
+                        .filter(whetherCollectionParamOfType).toList();
+
+                final ImmutableList<ObjectActionParameter> 
compatibleScalarParams = FluentIterable.from(parameters)
+                        .filter(whetherScalarParamOfType).toList();
+
                 // for collection parameters, install an defaults facet (if 
there isn't one already)
                 // this will cause the UI to render the collection with 
toggleboxes
                 // with a thread-local used to provide the selected objects
-                final ImmutableList<ObjectActionParameter> collectionParams = 
FluentIterable.from(parameters)
-                        .filter(whetherCollectionParamOfType).toList();
-                for (final ObjectActionParameter collectionParam : 
collectionParams) {
+                for (final ObjectActionParameter collectionParam : 
compatibleCollectionParams) {
                     final ActionParameterDefaultsFacet defaultsFacet = 
collectionParam
                             .getFacet(ActionParameterDefaultsFacet.class);
                     if (existsAndNotDerived(defaultsFacet)) {
@@ -105,28 +112,39 @@ public class 
ActionCollectionParameterDefaultsAndChoicesPostProcessor implements
                     }
                 }
 
-                // for both scalar and collection parameters, install a 
choices facet (if there isn't one already)
+                // for compatible collection parameters, install a choices 
facet (if there isn't one already)
+                // using the associated collection for its values
+                for (final ObjectActionParameter collectionParam : 
compatibleCollectionParams) {
+                    addChoicesFacetIfNoneAlready(otma, collectionParam);
+                }
+
+                // similarly for compatible scalar parameters, install a 
choices facet (if there isn't one already)
                 // using the associated collection for its values.
-                for (final ObjectActionParameter scalarOrCollectionParam : 
parameters) {
-
-                    final ActionParameterChoicesFacet choicesFacet = 
scalarOrCollectionParam
-                            .getFacet(ActionParameterChoicesFacet.class);
-                    final ActionParameterAutoCompleteFacet autoCompleteFacet = 
scalarOrCollectionParam
-                            .getFacet(ActionParameterAutoCompleteFacet.class);
-                    if (existsAndNotDerived(choicesFacet) || 
existsAndNotDerived(autoCompleteFacet)) {
-                        // don't overwrite existing choices or autoComplete 
facet
-                    } else {
-                        FacetUtil.addFacet(
-                                new 
ActionParameterChoicesFacetFromParentedCollection(
-                                        scalarOrCollectionParam, otma,
-                                        getDeploymentCategory(), 
specificationLoader,
-                                        authenticationSessionProvider, 
adapterManager ));
-                    }
+                for (final ObjectActionParameter scalarParam : 
compatibleScalarParams) {
+                    addChoicesFacetIfNoneAlready(otma, scalarParam);
                 }
             }
         }
     }
 
+    private void addChoicesFacetIfNoneAlready(
+            final OneToManyAssociation otma,
+            final ObjectActionParameter scalarOrCollectionParam) {
+        final ActionParameterChoicesFacet choicesFacet = 
scalarOrCollectionParam
+                .getFacet(ActionParameterChoicesFacet.class);
+        final ActionParameterAutoCompleteFacet autoCompleteFacet = 
scalarOrCollectionParam
+                .getFacet(ActionParameterAutoCompleteFacet.class);
+        if (existsAndNotDerived(choicesFacet) || 
existsAndNotDerived(autoCompleteFacet)) {
+            // don't overwrite existing choices or autoComplete facet
+        } else {
+            FacetUtil.addFacet(
+                    new ActionParameterChoicesFacetFromParentedCollection(
+                            scalarOrCollectionParam, otma,
+                            getDeploymentCategory(), specificationLoader,
+                            authenticationSessionProvider, adapterManager ));
+        }
+    }
+
     private static boolean existsAndNotDerived(final Facet facet) {
         return facet != null && !facet.isNoop() && !facet.isNoop();
     }
diff --git 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/CollectionPanel.java
 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/CollectionPanel.java
index cdbf1e5..e5724e4 100644
--- 
a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/CollectionPanel.java
+++ 
b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collection/CollectionPanel.java
@@ -193,9 +193,10 @@ public class CollectionPanel extends 
PanelAbstract<EntityCollectionModel> implem
             collectionModel.clearToggleMementosList();
 
             final ObjectAdapterToggleboxColumn toggleboxColumn = 
bulkActionsProvider.getToggleboxColumn();
-            toggleboxColumn.clearToggles();
-
-            target.add(collectionPanel);
+            if(toggleboxColumn != null) {
+                toggleboxColumn.clearToggles();
+                target.add(collectionPanel);
+            }
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
danhayw...@apache.org.

Reply via email to