myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r453897 - /myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java
Date Sat, 07 Oct 2006 13:03:05 GMT
Author: baranda
Date: Sat Oct  7 06:03:05 2006
New Revision: 453897

URL: http://svn.apache.org/viewvc?view=rev&rev=453897
Log:
Reduced repetitive code by creating the evaluateValueExpression(ELContext,ValueExpression)
util method

Modified:
    myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java

Modified: myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java
URL: http://svn.apache.org/viewvc/myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java?view=diff&rev=453897&r1=453896&r2=453897
==============================================================================
--- myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java
(original)
+++ myfaces/shared/branches/3_0_0/core/src/main/java/org/apache/myfaces/shared/taglib/UIComponentTagUtils.java
Sat Oct  7 06:03:05 2006
@@ -33,6 +33,7 @@
 import javax.faces.validator.MethodExpressionValidator;
 import javax.el.ValueExpression;
 import javax.el.MethodExpression;
+import javax.el.ELContext;
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
@@ -67,16 +68,11 @@
                                           String propName,
                                           ValueExpression value)
     {
-        if (value != null)
+        String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+
+        if (strValue != null)
         {
-            if (value.isLiteralText())
-            {
-                component.getAttributes().put(propName, Integer.valueOf(value.getExpressionString()));
-            }
-            else
-            {
-                component.setValueExpression(propName, value);
-            }
+            component.getAttributes().put(propName, Integer.valueOf(value.getExpressionString()));
         }
     }
 
@@ -89,16 +85,11 @@
                                        String propName,
                                        ValueExpression value)
     {
-        if (value != null)
+        String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+
+        if (strValue != null)
         {
-            if (value.isLiteralText())
-            {
-                component.getAttributes().put(propName, Long.valueOf(value.getExpressionString()));
-            }
-            else
-            {
-                component.setValueExpression(propName, value);
-            }
+            component.getAttributes().put(propName, Long.valueOf(value.getExpressionString()));
         }
     }
 
@@ -110,16 +101,11 @@
                                      String propName,
                                      ValueExpression value)
     {
-        if (value != null)
+        String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+
+        if (strValue != null)
         {
-            if (value.isLiteralText())
-            {
-                component.getAttributes().put(propName, value.getExpressionString());
-            }
-            else
-            {
-                component.setValueExpression(propName, value);
-            }
+            component.getAttributes().put(propName, value.getExpressionString());
         }
     }
 
@@ -131,16 +117,11 @@
                                       String propName,
                                       ValueExpression value)
     {
-        if (value != null)
+        String strValue = (String) evaluateValueExpression(context.getELContext(), value);
+
+        if (strValue != null)
         {
-            if (value.isLiteralText())
-            {
-                component.getAttributes().put(propName, Boolean.valueOf(value.getExpressionString()));
-            }
-            else
-            {
-                component.setValueExpression(propName, value);
-            }
+            component.getAttributes().put(propName, Boolean.valueOf(value.getExpressionString()));
         }
     }
 
@@ -306,6 +287,21 @@
 
             ((EditableValueHolder)component).addValueChangeListener(
                     new MethodExpressionValueChangeListener(valueChangedListener));
+        }
+    }
+
+    /**
+     * @since 1.2
+     */
+    public static Object evaluateValueExpression(ELContext elContext, ValueExpression valueExpression
)
+    {
+        if (valueExpression.isLiteralText())
+        {
+            return valueExpression.getExpressionString();
+        }
+        else
+        {
+            return valueExpression.getValue(elContext);
         }
     }
 



Mime
View raw message