You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2019/11/04 15:12:48 UTC

[empire-db] branch master updated: EMPIREDB-282 Code cleanup and small MenuListTag bugfix

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

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 4753d8c  EMPIREDB-282 Code cleanup and small MenuListTag bugfix
4753d8c is described below

commit 4753d8ce4c781ceb6fbc2a516c3bbaffeacaae8e
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Mon Nov 4 16:12:44 2019 +0100

    EMPIREDB-282
    Code cleanup and small MenuListTag bugfix
---
 .../apache/empire/jsf2/components/MenuListTag.java | 106 +++++++++------------
 .../empire/jsf2/utils/TagEncodingHelper.java       |  18 ++--
 2 files changed, 56 insertions(+), 68 deletions(-)

diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuListTag.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuListTag.java
index d840389..5bdbd6a 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuListTag.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/MenuListTag.java
@@ -34,14 +34,23 @@ import org.apache.empire.jsf2.utils.TagEncodingHelperFactory;
 public class MenuListTag extends UIOutput implements NamingContainer
 {
     // Logger
-    // private static final Logger log = LoggerFactory.getLogger(MenuTag.class);
+    // private static final Logger log = LoggerFactory.getLogger(MenuListTag.class);
     
     protected final TagEncodingHelper helper = TagEncodingHelperFactory.create(this, "eMenuList");
     
+    private enum Properties
+    {
+        currentId,
+        currentClass,
+        parentClass,
+        disabledClass,
+        expandedClass,
+        itemWrapTag,
+        defaultItemClass;
+    }
+    
     protected String currentId = null; 
     protected String currentClass = null; 
-    // protected String prevMenuId = null; 
-    // protected String enabledClass = null; 
     protected String parentClass = null;
     protected String disabledClass = null; 
     protected String expandedClass = null;
@@ -104,26 +113,13 @@ public class MenuListTag extends UIOutput implements NamingContainer
     
     protected void initMenuAttributes(FacesContext context)
     {        
-        currentId       = helper.getTagAttributeString("currentId"); 
-        currentClass    = helper.getTagAttributeString("currentClass"); 
-        // enabledClass = StringUtils.toString(map.get("enabledClass")); 
-        disabledClass   = helper.getTagAttributeString("disabledClass"); 
-        parentClass     = helper.getTagAttributeString("parentClass");
-        expandedClass   = helper.getTagAttributeString("expandedClass");
-        itemWrapTag     = helper.getTagAttributeString("itemWrapTag");
-        defaultItemClass = helper.getTagAttributeString("defaultItemClass");
-
-        // remember previousMenu (may be used by JavaScript)
-        /*
-        if (currentId!=null)
-        {   // StoreID on Session and set lastId
-            Map<String,Object> sessionMap = context.getExternalContext().getSessionMap();
-            String attrName = this.getClientId()+":prevMenuId";
-            prevMenuId = StringUtils.toString(sessionMap.get(attrName));
-            if (StringUtils.compareEqual(prevMenuId, currentId, false)==false)
-                sessionMap.put(attrName, currentId);
-        }
-        */
+        currentId        = helper.getTagAttributeString(Properties.currentId.name()); 
+        currentClass     = helper.getTagAttributeString(Properties.currentClass.name()); 
+        disabledClass    = helper.getTagAttributeString(Properties.disabledClass.name()); 
+        parentClass      = helper.getTagAttributeString(Properties.parentClass.name());
+        expandedClass    = helper.getTagAttributeString(Properties.expandedClass.name());
+        itemWrapTag      = helper.getTagAttributeString(Properties.itemWrapTag.name());
+        defaultItemClass = helper.getTagAttributeString(Properties.defaultItemClass.name());
 
         // find parent
         MenuListTag parent = getParentMenu();
@@ -134,8 +130,6 @@ public class MenuListTag extends UIOutput implements NamingContainer
             currentId = parent.getCurrentId();
         if (currentClass==null)
             currentClass = parent.getCurrentClass();  
-        // if (enabledClass==null)
-        //     enabledClass = parent.getEnabledClass();
         if (disabledClass==null)
             disabledClass = parent.getDisabledClass();
         if (parentClass==null)
@@ -143,7 +137,7 @@ public class MenuListTag extends UIOutput implements NamingContainer
         if (expandedClass==null)
             expandedClass = parent.getExpandedClass();
         if (itemWrapTag==null)
-            itemWrapTag = parent.itemWrapTag;
+            itemWrapTag = parent.getItemWrapTag();
         if (defaultItemClass==null)
             defaultItemClass = parent.defaultItemClass;
         
@@ -168,45 +162,43 @@ public class MenuListTag extends UIOutput implements NamingContainer
     
     public String getCurrentId()
     {
+        if (currentId==null)
+            currentId= StringUtils.toString(getStateHelper().get(Properties.currentId));
         return currentId;
     }
 
     public String getCurrentClass()
     {
+        if (currentClass==null)
+            currentClass= StringUtils.toString(getStateHelper().get(Properties.currentClass));
         return currentClass;
     }
-    
-    /*
-    public String getPreviousMenuId()
-    {
-        return prevMenuId;
-    }
-    */
-
-    /*
-    public String getEnabledClass()
-    {
-        return enabledClass;
-    }
-    */
 
     public String getDisabledClass()
     {
+        if (disabledClass==null)
+            disabledClass= StringUtils.toString(getStateHelper().get(Properties.disabledClass));
         return disabledClass;
     }
 
     public String getParentClass()
     {
+        if (parentClass==null)
+            parentClass= StringUtils.toString(getStateHelper().get(Properties.parentClass));
         return parentClass;
     }
 
     public String getExpandedClass()
     {
+        if (expandedClass==null)
+            expandedClass= StringUtils.toString(getStateHelper().get(Properties.expandedClass));
         return expandedClass;
     }
 
     public String getItemWrapTag()
     {
+        if (itemWrapTag==null)
+            itemWrapTag= StringUtils.toString(getStateHelper().get(Properties.itemWrapTag));
         return itemWrapTag;
     }
     
@@ -228,53 +220,43 @@ public class MenuListTag extends UIOutput implements NamingContainer
     public void setCurrentId(String currentId)
     {
         this.currentId = currentId;
+        // save
+        getStateHelper().put(Properties.currentId, currentId);
     }
 
     public void setCurrentClass(String currentClass)
     {
         this.currentClass = currentClass;
+        // save
+        getStateHelper().put(Properties.currentClass, currentClass);
     }
 
-    /*
-    public void setEnabledClass(String enabledClass)
-    {
-        this.enabledClass = enabledClass;
-    }
-    */
-
     public void setDisabledClass(String disabledClass)
     {
         this.disabledClass = disabledClass;
+        // save
+        getStateHelper().put(Properties.disabledClass, disabledClass);
     }
 
     public void setParentClass(String parentClass)
     {
         this.parentClass = parentClass;
+        // save
+        getStateHelper().put(Properties.parentClass, parentClass);
     }
 
     public void setExpandedClass(String expandedClass)
     {
         this.expandedClass = expandedClass;
+        // save
+        getStateHelper().put(Properties.expandedClass, expandedClass);
     }
 
     public void setItemWrapTag(String itemWrapTag)
     {
         this.itemWrapTag = itemWrapTag;
+        // save
+        getStateHelper().put(Properties.itemWrapTag, itemWrapTag);
     }
 
-    /*
-    protected void writeAttribute(ResponseWriter writer, Map<String, Object> map, String attribute, String targetName)
-        throws IOException
-    {
-        Object value = map.get(attribute);
-        if (value != null)
-            writer.writeAttribute(targetName, value, null);
-    }
-    protected void writeAttribute(ResponseWriter writer, Map<String, Object> map, String attribute)
-        throws IOException
-    {
-        writeAttribute(writer, map, attribute, attribute);
-    }
-    */
-
 }
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
index 74386ea..45c8724 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
@@ -314,11 +314,9 @@ public class TagEncodingHelper implements NamingContainer
                 return;
             // Make sure null values are not forced to be required
             boolean isNull = ObjectUtils.isEmpty(value);
-            if (isNull)
-            {   // Check Required
-                if (isRequired())
-                    throw new FieldNotNullException(column);
-                return; // not required
+            if (isNull && validateNullValue())
+            {   // OK, null allowed
+                return;
             }
             // validate through record (if any)
             if ((getRecord() instanceof Record))
@@ -652,7 +650,7 @@ public class TagEncodingHelper implements NamingContainer
         this.record = record;
         this.mostRecentValue = null; 
     }
-
+    
     public Object findRecordComponent()
     {
         // already present?
@@ -867,6 +865,14 @@ public class TagEncodingHelper implements NamingContainer
         // Required
         return getColumn().isRequired();
     }
+
+    public boolean validateNullValue()
+    {
+        if (isValueRequired())
+            throw new FieldNotNullException(column);
+        // OK, null allowed
+        return true;
+    }
     
     /**
      * used for partial submits to detect whether the value of this field can be set to null