Ate Douma pushed to branch master at cms-community / hippo-cms

Commits:
55debee2 by Ate Douma at 2017-11-29T15:43:14+01:00
CMS-10813 Fix non-serializable problem with ConfigurationService instance

- - - - -


2 changed files:

- 
console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/NodeEditor.java
- 
console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/PropertiesEditor.java


Changes:

=====================================
console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/NodeEditor.java
=====================================
--- 
a/console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/NodeEditor.java
+++ 
b/console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/NodeEditor.java
@@ -72,15 +72,17 @@ class NodeEditor extends Form<Node> {
     private String category;
     @SuppressWarnings("unused FieldCanBeLocal")
     private String origin;
+    @SuppressWarnings("unused FieldCanBeLocal")
     private String primaryTypeOrigin;
+    @SuppressWarnings("unused FieldCanBeLocal")
     private String mixinTypesOrigin;
 
     private NamespaceProvider namespaceProvider;
     private NamespacePropertiesEditor namespacePropertiesEditor;
     private NodeTypesEditor typesEditor;
 
-    // get the HCM ConfigurationService, which is repo-static, but not the 
model, which can be updated
-    private final ConfigurationService cfgService = 
HippoServiceRegistry.getService(ConfigurationService.class);
+    // the (transient, not serializable) HCM ConfigurationService, which is 
repo-static, but not the model, which can be updated
+    private transient ConfigurationService cfgService;
 
     NodeEditor(String id, IModel<Node> model) {
         super(id, model);
@@ -127,6 +129,19 @@ class NodeEditor extends Form<Node> {
     }
 
     @Override
+    protected void onDetach() {
+        super.onDetach();
+        cfgService = null;
+    }
+
+    private ConfigurationService getConfigurationService() {
+        if (cfgService == null) {
+            cfgService = 
HippoServiceRegistry.getService(ConfigurationService.class);
+        }
+        return cfgService;
+    }
+
+    @Override
     public void onModelChanged() {
         super.onModelChanged();
         final IModel<Node> model = getModel();
@@ -145,7 +160,7 @@ class NodeEditor extends Form<Node> {
                 namespacePropertiesEditor.setVisible(true);
 
                 // update HCM category & origin(s)
-                final ConfigurationModel cfgModel = 
cfgService.getRuntimeConfigurationModel();
+                final ConfigurationModel cfgModel = 
getConfigurationService().getRuntimeConfigurationModel();
                 origin = PropertiesEditor.getNodeOrigin(nodePath, cfgModel);
                 primaryTypeOrigin = 
PropertiesEditor.getPropertyOrigin((nodePath.equals("/")? "": nodePath) + 
"/jcr:primaryType", cfgModel);
                 mixinTypesOrigin = 
PropertiesEditor.getPropertyOrigin((nodePath.equals("/")? "": nodePath) + 
"/jcr:mixinTypes", cfgModel);


=====================================
console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/PropertiesEditor.java
=====================================
--- 
a/console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/PropertiesEditor.java
+++ 
b/console/frontend/src/main/java/org/hippoecm/frontend/plugins/console/editor/PropertiesEditor.java
@@ -64,7 +64,8 @@ public class PropertiesEditor extends DataView<Property> {
     static final Logger log = LoggerFactory.getLogger(PropertiesEditor.class);
 
     private String namespacePrefix;
-    private final ConfigurationService cfgService = 
HippoServiceRegistry.getService(ConfigurationService.class);
+    // the (transient, not serializable) HCM ConfigurationService, which is 
repo-static, but not the model, which can be updated
+    private transient ConfigurationService cfgService;
 
     public PropertiesEditor(String id, IDataProvider<Property> model) {
         super(id, model);
@@ -81,6 +82,19 @@ public class PropertiesEditor extends DataView<Property> {
     }
 
     @Override
+    protected void onDetach() {
+        super.onDetach();
+        cfgService = null;
+    }
+
+    private ConfigurationService getConfigurationService() {
+        if (cfgService == null) {
+            cfgService = 
HippoServiceRegistry.getService(ConfigurationService.class);
+        }
+        return cfgService;
+    }
+
+    @Override
     protected void populateItem(Item item) {
         JcrPropertyModel model = (JcrPropertyModel) item.getModel();
 
@@ -110,7 +124,7 @@ public class PropertiesEditor extends DataView<Property> {
             addLink.setVisible(definition.isMultiple() && 
!definition.isProtected());
 
             // HCM config-tracing info
-            final ConfigurationModel cfgModel = 
cfgService.getRuntimeConfigurationModel();
+            final ConfigurationModel cfgModel = 
getConfigurationService().getRuntimeConfigurationModel();
             String origin = getPropertyOrigin(model.getProperty().getPath(), 
cfgModel);
             item.add(new Label("origin", "").add(new 
OriginTitleBehavior(Model.of(origin))));
         } catch (RepositoryException e) {



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-cms/commit/55debee2d9c4d3d8f44436ce112b93d8766d090e

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-cms/commit/55debee2d9c4d3d8f44436ce112b93d8766d090e
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to