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 2beec35  EMPIREDB-306 Improve JSF taglib support
2beec35 is described below

commit 2beec355ce4923fa19b529b81459a3fc8c66acbe
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Sep 24 19:42:36 2019 +0200

    EMPIREDB-306
    Improve JSF taglib support
---
 empire-db-examples/empire-db-example-jsf2/pom.xml  |  8 ---
 empire-db-jsf2/pom.xml                             |  5 +-
 .../apache/empire/jsf2/components/ControlTag.java  |  4 +-
 .../apache/empire/jsf2/components/InputTag.java    |  5 +-
 .../empire/jsf2/utils/TagEncodingHelper.java       | 69 +++++++++++++---------
 pom.xml                                            |  5 ++
 6 files changed, 56 insertions(+), 40 deletions(-)

diff --git a/empire-db-examples/empire-db-example-jsf2/pom.xml 
b/empire-db-examples/empire-db-example-jsf2/pom.xml
index fcc21b4..0164451 100644
--- a/empire-db-examples/empire-db-example-jsf2/pom.xml
+++ b/empire-db-examples/empire-db-example-jsf2/pom.xml
@@ -71,14 +71,6 @@
                        <artifactId>myfaces-impl</artifactId>
                </dependency>
 
-               <dependency>
-                       <groupId>org.apache.tomcat</groupId>
-                       <artifactId>el-api</artifactId>
-                       <version>6.0.30</version>
-                       <type>jar</type>
-                       <scope>provided</scope>
-               </dependency>
-
         <!-- use log4j for logging -->
                <dependency>
                        <groupId>org.slf4j</groupId>
diff --git a/empire-db-jsf2/pom.xml b/empire-db-jsf2/pom.xml
index d1f46c4..e49618a 100644
--- a/empire-db-jsf2/pom.xml
+++ b/empire-db-jsf2/pom.xml
@@ -60,9 +60,8 @@
                </dependency>
                <!-- EL --> 
                <dependency>
-                       <groupId>org.apache.tomcat</groupId>
-                       <artifactId>el-api</artifactId>
-                       <version>6.0.33</version>
+                   <groupId>org.apache.tomcat</groupId>
+                   <artifactId>tomcat-el-api</artifactId>
                        <type>jar</type>
                        <scope>provided</scope>
                </dependency>
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
index 2e98857..91e7a77 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/ControlTag.java
@@ -385,7 +385,9 @@ public class ControlTag extends UIInput implements 
NamingContainer
     
     @Override
     public void setId(String id) 
-    {
+    {   // complete
+        id = helper.completeInputTagId(id); 
+        // set
         super.setId(id);
         // reset record
         helper.setRecord(null);
diff --git 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
index acb1cc6..e3ab79b 100644
--- 
a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
+++ 
b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/components/InputTag.java
@@ -30,6 +30,7 @@ import javax.faces.context.FacesContext;
 import javax.faces.convert.ConverterException;
 import javax.faces.view.AttachedObjectHandler;
 
+import org.apache.empire.commons.StringUtils;
 import org.apache.empire.data.Column;
 import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.exceptions.FieldIllegalValueException;
@@ -208,7 +209,9 @@ public class InputTag extends UIInput implements 
NamingContainer
 
     @Override
     public void setId(String id)
-    {
+    {   // complete
+        id = helper.completeInputTagId(id); 
+        // setId
         super.setId(id);
         // reset record
         helper.setRecord(null);
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 03c3fd8..8452b35 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
@@ -23,7 +23,9 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.Iterator;
 import java.util.Locale;
 
+import javax.el.ELContext;
 import javax.el.ValueExpression;
+import javax.el.ValueReference;
 import javax.faces.FacesWrapper;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.NamingContainer;
@@ -340,9 +342,13 @@ public class TagEncodingHelper implements NamingContainer
         
         @Override
         public String getInputId()
-        {
-            Column c = getColumn();
-            return c.getName(); // (c instanceof DBColumn) ? 
((DBColumn)c).getFullName() : c.getName();
+        {   /**
+             * obsolete since ControlTag or InputTag will set column name as id
+             * 
+             Column c = getColumn();
+             return c.getName();
+            */
+            return "inp";
         }
         
         @Override
@@ -378,7 +384,7 @@ public class TagEncodingHelper implements NamingContainer
     private Object              record       = null;
     private RecordTag           recordTag    = null;
     // private Boolean          tagRequired  = null;
-    private Boolean             hasValueExpr = null;
+    private Boolean             hasValueRef  = null;
     private InputControl        control      = null;
     private TextResolver        textResolver = null;
     private Object              mostRecentValue = null;
@@ -414,6 +420,17 @@ public class TagEncodingHelper implements NamingContainer
         }
     }
 
+    public String completeInputTagId(String id)
+    {
+        if (StringUtils.isEmpty(id))
+            return getColumnName();
+        // check
+        if (id.indexOf("{column}")>0)
+            id = id.replace("{column}", getColumnName());
+        // done 
+        return id;
+    }
+    
     public InputControl getInputControl()
     {
         if (control != null)
@@ -699,7 +716,7 @@ public class TagEncodingHelper implements NamingContainer
             if (!(record instanceof Record) || ((Record) record).isReadOnly())
                 return true;
         }
-        else if (!hasValueExpression())
+        else if (!hasValueReference())
         { // No Value expression given
             return true;
         }
@@ -757,7 +774,7 @@ public class TagEncodingHelper implements NamingContainer
             return r.isFieldRequired(getColumn());
         }
         // Check Value Attribute
-        if (hasValueExpression())
+        if (hasValueReference())
             return false;
         // Required
         return getColumn().isRequired();
@@ -847,7 +864,7 @@ public class TagEncodingHelper implements NamingContainer
         if (rec != null)
             return rec;
         // Value expression
-        if (hasValueExpression())
+        if (hasValueReference())
         {   // See if the record is in value
             return null;
         }
@@ -865,34 +882,32 @@ public class TagEncodingHelper implements NamingContainer
         return rec;
     }
     
-    protected boolean hasValueExpression()
+    protected boolean hasValueReference()
     {
         // Find expression
-        if (hasValueExpr != null)
-            return hasValueExpr.booleanValue();
+        if (hasValueRef != null)
+            return hasValueRef.booleanValue();
         // Find expression
+        boolean hasVR = false;
         ValueExpression ve = findValueExpression("value", false);
         if (ve != null)
         {   // check
-            if (log.isDebugEnabled())
-            {
-                FacesContext ctx = FacesContext.getCurrentInstance();
-                boolean readOnly = ve.isReadOnly(ctx.getELContext());
-                if (readOnly)
-                    log.debug(tag.getClass().getSimpleName() + " for " + 
getColumnName() + " expression " + ve.getExpressionString()
-                              + " is readOnly!");
-                else
-                    log.debug(tag.getClass().getSimpleName() + " for " + 
getColumnName() + " expression " + ve.getExpressionString()
-                              + " is updateable!");
+            ELContext elc = FacesContext.getCurrentInstance().getELContext();
+            ValueReference vr = ve.getValueReference(elc);
+            if (vr!=null && log.isDebugEnabled())  
+            {   // log value reference
+                Object base = vr.getBase();
+                Object property = vr.getProperty();
+                String writeable = (ve.isReadOnly(elc) ? "read-only" : 
"updateable");
+                String beanName = (base!=null ? 
base.getClass().getSimpleName() : "{NULL}");
+                log.debug("Tag-ValueExpression for {} on {}.{} is {}. 
Expression is \"{}\".", getColumnName(), beanName, property, writeable, 
ve.getExpressionString());
             }
+            // set result
+            hasVR = (vr!=null);
         }
-        /*
-        else if (log.isDebugEnabled())
-            log.debug(tag.getClass().getSimpleName()+" for "+getColumnName()+" 
has no value expression!");
-        */
-        // merken
-        hasValueExpr = Boolean.valueOf(ve != null);
-        return hasValueExpr.booleanValue();
+        // store result to avoid multiple detection 
+        hasValueRef = Boolean.valueOf(hasVR);
+        return hasValueRef.booleanValue();
     }
     
     private static final String CC_ATTR_EXPR = "#{cc.attrs.";
diff --git a/pom.xml b/pom.xml
index 3673d73..c4c8368 100644
--- a/pom.xml
+++ b/pom.xml
@@ -370,6 +370,11 @@
                                <artifactId>myfaces-impl</artifactId>
                                <version>2.2.12</version>
                        </dependency>
+                       <dependency>
+                           <groupId>org.apache.tomcat</groupId>
+                           <artifactId>tomcat-el-api</artifactId>
+                           <version>8.0.48</version>
+                       </dependency>
                <!-- Misc -->
                        <dependency>
                                <groupId>junit</groupId>

Reply via email to