empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1378747 - /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
Date Wed, 29 Aug 2012 21:37:01 GMT
Author: doebele
Date: Wed Aug 29 21:37:01 2012
New Revision: 1378747

URL: http://svn.apache.org/viewvc?rev=1378747&view=rev
Log:
EMPIREDB-157 
JSF2 allow to override required state with mandatory attribute

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java?rev=1378747&r1=1378746&r2=1378747&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/utils/TagEncodingHelper.java
Wed Aug 29 21:37:01 2012
@@ -325,6 +325,7 @@ public class TagEncodingHelper implement
     private Column              column       = null;
     private Object              record       = null;
     private RecordTag           recordTag    = null;
+    private Boolean             tagRequired  = null;
     private Boolean             hasValueExpr = null;
     private InputControl        control      = null;
     private TextResolver        textResolver = null;
@@ -339,7 +340,7 @@ public class TagEncodingHelper implement
     public void encodeBegin()
     {
         if (tag instanceof UIInput)
-        {   /* has local value? */
+        {   // has local value?
             if (((UIInput)tag).isLocalValueSet())
             {   /* clear local value */
                 if (log.isDebugEnabled())
@@ -347,6 +348,13 @@ public class TagEncodingHelper implement
                 ((UIInput)tag).setValue(null);
                 ((UIInput)tag).setLocalValueSet(false);
             }
+            // See if the Input is required 
+            ValueExpression ve = findValueExpression("mandatory", true);
+            if (ve!=null)
+            {   Object req = ve.getValue(FacesContext.getCurrentInstance().getELContext());
+                if (req!=null)
+                    tagRequired = new Boolean(ObjectUtils.getBoolean(req));
+            }    
         }
     }
 
@@ -531,7 +539,7 @@ public class TagEncodingHelper implement
                 if (value!=null && (tag instanceof UIInput) && !((UIInput)tag).isLocalValueSet())
                     value= null; /* should never come here! */
                 if (value==null)
-                    value = findValueExpression();
+                    value = findValueExpression("value", false);
                 
                 // value = tag.getValue();
                 return value;
@@ -601,7 +609,7 @@ public class TagEncodingHelper implement
             if (!(record instanceof Record) || ((Record) record).isReadOnly())
                 return true;
         }
-        else if (!hasValueAttribute() || hasValueExpr == null)
+        else if (!hasValueExpression())
         { // No Value expression given
             return true;
         }
@@ -648,11 +656,9 @@ public class TagEncodingHelper implement
 
     public boolean isValueRequired()
     {
-        /*
-        Object required = tag.getAttributes().get("mandatory");
-        if (required != null)
-            return ObjectUtils.getBoolean(required);
-        */    
+        // See if the tag is required
+        if (tagRequired!=null)
+            return tagRequired.booleanValue();
         // Check Read-Only first
         if (isReadOnly())
             return false;
@@ -663,7 +669,7 @@ public class TagEncodingHelper implement
             return r.isFieldRequired(getColumn());
         }
         // Check Value Attribute
-        if (hasValueAttribute() && (hasValueExpr==null || hasValueExpr.booleanValue()))
+        if (hasValueExpression())
             return false;
         // Required
         return getColumn().isRequired();
@@ -741,7 +747,7 @@ public class TagEncodingHelper implement
     {
         Object rec = tag.getAttributes().get("record");
 
-        if (rec == null && hasValueAttribute())
+        if (rec == null && hasValueExpression())
         {   // See if the record is in value
             return null;
         }
@@ -761,21 +767,13 @@ public class TagEncodingHelper implement
         return rec;
     }
     
-    protected boolean hasValueAttribute()
+    protected boolean hasValueExpression()
     {
-        /* this does not work - nor might it be necessary
-        // direct value is set (no expression)
-        if (tag.getAttributes().containsKey("value"))
-            return true;
-        Object v = tag.getLocalValue(); // will be set for input controls that have an error
set
-        if (v!=null)
-            v=null;
-        */    
         // Find expression
         if (hasValueExpr != null)
             return hasValueExpr.booleanValue();
         // Find expression
-        ValueExpression ve = findValueExpression();
+        ValueExpression ve = findValueExpression("value", false);
         if (ve != null)
         {   // check
             if (log.isDebugEnabled())
@@ -801,10 +799,10 @@ public class TagEncodingHelper implement
     
     private static final String CC_ATTR_EXPR = "#{cc.attrs.";
 
-    protected ValueExpression findValueExpression()
+    protected ValueExpression findValueExpression(String attribute, boolean allowLiteral)
     {
         // Check for expression
-        ValueExpression ve = tag.getValueExpression("value");
+        ValueExpression ve = tag.getValueExpression(attribute);
         if (ve == null)
             return null;
         // Find expression
@@ -836,11 +834,17 @@ public class TagEncodingHelper implement
             String attrib = expr.substring(CC_ATTR_EXPR.length(), end);
             if (attrib.indexOf('.')>0)
                 return ve; // do not investigate any further
-            // find attribute 
-            ve = parent.getValueExpression(attrib);
-            if (ve == null)
+            // find attribute
+            ValueExpression next = parent.getValueExpression(attrib);
+            if (next == null)
+            {   // allow literal
+                if (allowLiteral && (parent.getAttributes().get(attrib)!=null))
+                    return ve;
+                // not found
                 return null;
+            }
             // get new expression String
+            ve = next;
             expr = ve.getExpressionString();
         }
         // found



Mime
View raw message