You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2008/10/15 08:07:13 UTC

svn commit: r704785 - in /myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main: java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts

Author: matzew
Date: Tue Oct 14 23:07:12 2008
New Revision: 704785

URL: http://svn.apache.org/viewvc?rev=704785&view=rev
Log:
TRINIDAD-1260

Thx to Blake Sullivan for his patch

Modified:
    myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java
    myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java?rev=704785&r1=704784&r2=704785&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java Tue Oct 14 23:07:12 2008
@@ -18,7 +18,15 @@
  */
 package org.apache.myfaces.trinidad.change;
 
+import java.io.Serializable;
+
+import java.util.Map;
+
+import javax.el.ValueExpression;
+
 import javax.faces.component.UIComponent;
+import javax.faces.el.ValueBinding;
+
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
 
 /**
@@ -35,8 +43,12 @@
    *         to be restored.
    * @param attributeValue The value of the attribute that needs to be restored.
    *         This value should be of type java.io.Serializable in order to be 
-   *         persisted.
-   * @throws IllegalArgumentException if specified attributeName were to be null.
+   *         persisted.  If the value is of type ValueExpression or ValueBinding,
+   *         the component's ValueBinding or ValueExpression for the attribute
+   *         will be updated and the current attribute value, if any, removed so
+   *         that the new ValueExpression or ValueBinding can take precedence.
+   * @throws IllegalArgumentException if specified attributeName were to be null or
+   *         the specified attributeValue isn't serializable
    */
   public AttributeComponentChange(
     String attributeName,
@@ -46,6 +58,11 @@
     if ((attributeName == null) || (attributeName.length() == 0))
       throw new IllegalArgumentException(_LOG.getMessage(
         "CANNOT_CONSTRUCT_ATTRIBUTECHANGE_WITH_NULL_NAME"));
+    
+    if (!(attributeValue instanceof Serializable))
+      throw new IllegalArgumentException(_LOG.getMessage(
+        "UNSERIALIZABLE_VALUE", attributeValue));
+      
     _attributeName = attributeName;
     _attributeValue = attributeValue;
   }
@@ -69,11 +86,30 @@
   /**
    * {@inheritDoc}
    */
-  @SuppressWarnings("unchecked")
   @Override
+  @SuppressWarnings("deprecation")
   public void changeComponent(UIComponent uiComponent)
   {
-    uiComponent.getAttributes().put(_attributeName, _attributeValue);
+    Map<String, Object> attributeMap = uiComponent.getAttributes();
+    
+    // if the attributevalue is a ValueExpression or ValueBinding, use the
+    // appropriate setValueExpression/setValueBinding call and remove the
+    // current attribute value, if any, so that the ValueExpression/ValueBinding
+    // can take precedence
+    if (_attributeValue instanceof ValueExpression)
+    {
+      uiComponent.setValueExpression(_attributeName, (ValueExpression)_attributeValue);
+      attributeMap.remove(_attributeName);
+    }
+    else if (_attributeValue instanceof ValueBinding)
+    {
+      uiComponent.setValueBinding(_attributeName, (ValueBinding)_attributeValue);
+      attributeMap.remove(_attributeName);
+    }
+    else
+    {
+      attributeMap.put(_attributeName, _attributeValue);
+    }
   }
 
   private final String _attributeName;

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=704785&r1=704784&r2=704785&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts Tue Oct 14 23:07:12 2008
@@ -399,6 +399,9 @@
 <!-- DEPRECATED_RELATIVE_ID_SYNTAX -->
 <resource key="DEPRECATED_RELATIVE_ID_SYNTAX">Could not find the component with scopedId {0} from {1} with the supported syntax. The component was found with the deprecated syntax. Please use the supported syntax.</resource>
 
+<!-- UNSERIALIZABLE_VALUE -->
+<resource key="UNSERIALIZABLE_VALUE">Unserializable value:{0}</resource>
+
 <!-- UNSERIALIZABLE_PROPERTY_VALUE -->
 <resource key="UNSERIALIZABLE_PROPERTY_VALUE">Unserializable value:{0} for key:{1} in container:{2}</resource>