You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by aw...@apache.org on 2007/07/17 00:32:57 UTC

svn commit: r556757 - /myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java

Author: awiner
Date: Mon Jul 16 15:32:56 2007
New Revision: 556757

URL: http://svn.apache.org/viewvc?view=rev&rev=556757
Log:
TRINIDAD-101: Menu Model is not created if its tree is empty
- Patch from Gary Kind

Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java?view=diff&rev=556757&r1=556756&r2=556757
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/menu/MenuContentHandlerImpl.java Mon Jul 16 15:32:56 2007
@@ -347,39 +347,54 @@
   @Override
   public void endDocument()
   {
-    _menuList = _menuNodes.get(0);
-    
-    // Create the treeModel
-    ChildPropertyTreeModel treeModel = 
-                  new ChildPropertyTreeModel(_menuList, "children");
-                  
-    // Put it in the map
-    _treeModelMap.put(_currentTreeModelMapKey, treeModel);
-    
-    // If Model is the Root, then build Model's hashmaps 
-    // and set them on the Root Model.
-    XMLMenuModel rootModel = getRootModel();
-    
-    if (rootModel == getModel())
+    if (_menuNodes.isEmpty())
     {
-      _viewIdFocusPathMap = new HashMap<String,List<Object>>();
-      _nodeFocusPathMap   = new HashMap<Object, List<Object>>();
-      _idNodeMap          = new HashMap<String, Object>();
-      Object oldPath      = treeModel.getRowKey(); 
-
-      treeModel.setRowKey(null);
-
-      // Populate the maps
-      _addToMaps(treeModel, _viewIdFocusPathMap, _nodeFocusPathMap, _idNodeMap);
+      // Empty tree is created to prevent
+      // later NPEs if menu model methods are called.
+      _LOG.warning ("CREATE_TREE_WARNING: Empty Tree!");
       
-      // Cache the maps.  There is a possibility of multiple
-      // root models so we must cache the maps on a per root model
-      // basis.
-      _viewIdFocusPathMapMap.put(_currentTreeModelMapKey, _viewIdFocusPathMap);
-      _nodeFocusPathMapMap.put(_currentTreeModelMapKey, _nodeFocusPathMap);
-      _idNodeMapMap.put(_currentTreeModelMapKey, _idNodeMap);
+      // Create empty treeModel
+      ChildPropertyTreeModel treeModel = new ChildPropertyTreeModel();
+                    
+      // Put it in the map
+      _treeModelMap.put(_currentTreeModelMapKey, treeModel);     
+    }
+    else
+    {
+      _menuList = _menuNodes.get(0);
+      
+      // Create the treeModel
+      ChildPropertyTreeModel treeModel = 
+                    new ChildPropertyTreeModel(_menuList, "children");
+                    
+      // Put it in the map
+      _treeModelMap.put(_currentTreeModelMapKey, treeModel);
+      
+      // If Model is the Root, then build Model's hashmaps 
+      // and set them on the Root Model.
+      XMLMenuModel rootModel = getRootModel();
       
-      treeModel.setRowKey(oldPath);
+      if (rootModel == getModel())
+      {
+        _viewIdFocusPathMap = new HashMap<String,List<Object>>();
+        _nodeFocusPathMap   = new HashMap<Object, List<Object>>();
+        _idNodeMap          = new HashMap<String, Object>();
+        Object oldPath      = treeModel.getRowKey(); 
+     
+        treeModel.setRowKey(null);
+     
+        // Populate the maps
+        _addToMaps(treeModel, _viewIdFocusPathMap, _nodeFocusPathMap, _idNodeMap);
+        
+        // Cache the maps.  There is a possibility of multiple
+        // root models so we must cache the maps on a per root model
+        // basis.
+        _viewIdFocusPathMapMap.put(_currentTreeModelMapKey, _viewIdFocusPathMap);
+        _nodeFocusPathMapMap.put(_currentTreeModelMapKey, _nodeFocusPathMap);
+        _idNodeMapMap.put(_currentTreeModelMapKey, _idNodeMap);
+        
+        treeModel.setRowKey(oldPath);
+      }
     }
   }