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 7254b9b  EMPIREDB-282 JSF-Tags: add new style attribute if value is 
empty (Null)
7254b9b is described below

commit 7254b9ba2c03c0c41cbbd0ce071bbfbb778f8dbf
Author: Rainer Döbele <[email protected]>
AuthorDate: Wed Oct 2 18:41:29 2019 +0200

    EMPIREDB-282
    JSF-Tags: add new style attribute if value is empty (Null)
---
 .../apache/empire/jsf2/controls/InputControl.java  |  9 +++++++
 .../empire/jsf2/utils/TagEncodingHelper.java       | 30 ++++++++++++++++++++--
 .../org/apache/empire/commons/StringUtils.java     | 28 ++++++++++++++++++++
 3 files changed, 65 insertions(+), 2 deletions(-)

diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
index 75d0646..1b67060 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/controls/InputControl.java
@@ -412,6 +412,8 @@ public abstract class InputControl
             Object value = reqMap.get(clientId);
             if (input.isLocalValueSet() == false)
                 input.setSubmittedValue(value);
+            // change the style
+            addRemoveValueNullStyle(input, ObjectUtils.isEmpty(value));
             return;
         }
         else if (input.getSubmittedValue() != null) //  && 
FacesUtils.isClearSubmittedValues(fc)
@@ -438,6 +440,8 @@ public abstract class InputControl
         { // Set the value
             value = formatInputValue(value, ii);
             input.setValue(value);
+            // change the style
+            addRemoveValueNullStyle(input, ObjectUtils.isEmpty(value));
         }
     }
 
@@ -595,6 +599,11 @@ public abstract class InputControl
         if (value != null)
             input.getAttributes().put(name, String.valueOf(value));
     }
+    
+    public void addRemoveValueNullStyle(UIInput input, boolean nullValue)
+    {
+        addRemoveStyle(input, " eValNull", nullValue);
+    }
 
     public void addRemoveDisabledStyle(UIInput input, boolean disabled)
     {
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 b76f0d7..e151873 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
@@ -1384,7 +1384,7 @@ public class TagEncodingHelper implements NamingContainer
 
         // styleClass
         if (StringUtils.isNotEmpty(styleClass))
-            label.setStyleClass(styleClass);
+            label.setStyleClass(completeLabelStyleClass(styleClass, required));
         
         // for 
         if (StringUtils.isNotEmpty(forInput) && !readOnly)
@@ -1422,7 +1422,6 @@ public class TagEncodingHelper implements NamingContainer
     
     public void updateLabelComponent(FacesContext context, HtmlOutputLabel 
label, String forInput)
     {
-        boolean hasMark = (label.getChildCount()>0);
         // Find Input Control (only if forInput Attribute has been set!)
         InputTag inputTag = null;
         if (StringUtils.isNotEmpty(forInput) && !forInput.equals("*"))
@@ -1435,6 +1434,11 @@ public class TagEncodingHelper implements NamingContainer
         }
         // Is the Mark required?
         boolean required = (inputTag!=null ? inputTag.isInputRequired() : 
isValueRequired());
+        // Style Class
+        String styleClass = label.getStyleClass();
+        label.setStyleClass(completeLabelStyleClass(styleClass, required));
+        // set mark
+        boolean hasMark = (label.getChildCount()>0);
         if (required==hasMark)
             return;
         // Add or remove the mark
@@ -1443,6 +1447,28 @@ public class TagEncodingHelper implements NamingContainer
         else
             label.getChildren().clear();
     }
+
+    protected String completeLabelStyleClass(String styleClass, boolean 
required)
+    {
+        final String LABEL_REQ_STYLE = " "+InputControl.STYLECLASS_REQUIRED;
+
+        boolean hasRequired = StringUtils.contains(styleClass, 
LABEL_REQ_STYLE);
+        if (required==hasRequired)
+            return styleClass; // no change
+        // must be empty at least
+        if (styleClass==null)
+            styleClass="";
+        // add or remove
+        if (required) {
+            styleClass += LABEL_REQ_STYLE;
+        }    
+        else
+        {   // remove both   
+            styleClass = StringUtils.remove(styleClass, LABEL_REQ_STYLE);
+        }    
+        // done
+        return styleClass;
+    }
     
     protected void addRequiredMark(HtmlOutputLabel label)
     {
diff --git a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java 
b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
index 424c257..67bd2d7 100644
--- a/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
+++ b/empire-db/src/main/java/org/apache/empire/commons/StringUtils.java
@@ -130,6 +130,34 @@ public class StringUtils
     }
 
     /**
+     * Returns true if the given substring is part of the string provided by 
value 
+     * 
+     * @param value the value to check
+     * @param substring the substring
+     * @return true if the given substring is part of the string provided by 
value 
+     */
+    public static boolean contains(String value, String substring)
+    {
+        if (value==null || substring==null)
+            return false;
+        return ((value.indexOf(substring))>=0);
+    }
+
+    /**
+     * Returns true if the given substring is part of the string provided by 
value 
+     * 
+     * @param value the value to check
+     * @param substring the substring
+     * @return true if the given substring is part of the string provided by 
value 
+     */
+    public static boolean notContains(String value, String substring)
+    {
+        if (value==null || substring==null)
+            return true;
+        return ((value.indexOf(substring))<0);
+    }
+
+    /**
      * Converts an array of objects to a string.
      * 
      * @param array array of objects

Reply via email to