You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bs...@apache.org on 2010/12/10 00:50:48 UTC
svn commit: r1044172 - in
/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad:
change/AttributeComponentChange.java change/RowKeySetAttributeChange.java
component/UIXComponentBase.java
Author: bsullivan
Date: Thu Dec 9 23:50:48 2010
New Revision: 1044172
URL: http://svn.apache.org/viewvc?rev=1044172&view=rev
Log:
Use a special AttributeComponentChange for RowKeySets that establishes context when getting the current value. Use new subclass when adding attribute changes in UIXComponentBase
Added:
myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java (with props)
Modified:
myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java
myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
Modified: myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java?rev=1044172&r1=1044171&r2=1044172&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java (original)
+++ myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/AttributeComponentChange.java Thu Dec 9 23:50:48 2010
@@ -110,32 +110,7 @@ public class AttributeComponentChange ex
}
else
{
- boolean putValue = true;
-
- // Specially handle RowKeySet case by replacing the contents of the RowKeySet in-place
- // rather than replacing the entire object. This keeps the mutable object instance from
- // changing
- if (_attributeValue instanceof RowKeySet)
- {
- Object oldValue = attributeMap.get(_attributeName);
-
- if (oldValue instanceof RowKeySet)
- {
- RowKeySet oldKeySet = (RowKeySet)oldValue;
-
- oldKeySet.clear();
- oldKeySet.addAll((RowKeySet)_attributeValue);
-
- // don't replace the RowKeySet
- putValue = false;
- }
- }
-
-
- if (putValue)
- {
- attributeMap.put(_attributeName, _attributeValue);
- }
+ attributeMap.put(_attributeName, _attributeValue);
}
}
Added: myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java?rev=1044172&view=auto
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java (added)
+++ myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java Thu Dec 9 23:50:48 2010
@@ -0,0 +1,119 @@
+package org.apache.myfaces.trinidad.change;
+
+import java.util.Map;
+
+import javax.el.ValueExpression;
+
+import javax.faces.component.ContextCallback;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.trinidad.model.RowKeySet;
+
+public class RowKeySetAttributeChange extends AttributeComponentChange
+{
+ public RowKeySetAttributeChange(String clientId, String propertyName, Object value)
+ {
+ super(propertyName, value);
+
+ if ((clientId == null) || (clientId.length() == 0))
+ throw new IllegalArgumentException("No clientId specified");
+
+ _clientId = clientId;
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public void changeComponent(UIComponent uiComponent)
+ {
+ Map<String, Object> attributeMap = uiComponent.getAttributes();
+
+ Object attributeValue = getAttributeValue();
+ String attributeName = getAttributeName();
+
+ // 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
+ {
+ boolean putValue = true;
+
+ // Specially handle RowKeySet case by replacing the contents of the RowKeySet in-place
+ // rather than replacing the entire object. This keeps the mutable object instance from
+ // changing
+ if (attributeValue instanceof RowKeySet)
+ {
+ ValueExpression expression = uiComponent.getValueExpression(attributeName);
+
+ Object oldValue;
+
+ if (expression != null)
+ {
+ final FacesContext context = FacesContext.getCurrentInstance();
+
+ RowKeySet[] outHolder = new RowKeySet[1];
+
+ uiComponent.invokeOnComponent(context,
+ _clientId,
+ new ExpressionEvaluator(expression, outHolder));
+
+ oldValue = outHolder[0];
+ }
+ else
+ {
+ oldValue = attributeMap.get(attributeName);
+ }
+
+ if (oldValue instanceof RowKeySet)
+ {
+ RowKeySet oldKeySet = (RowKeySet)oldValue;
+
+ oldKeySet.clear();
+ oldKeySet.addAll((RowKeySet)attributeValue);
+
+ // don't replace the RowKeySet
+ putValue = false;
+ }
+ }
+
+
+ if (putValue)
+ {
+ attributeMap.put(attributeName, attributeValue);
+ }
+ }
+ }
+
+ private static final class ExpressionEvaluator implements ContextCallback
+ {
+ public ExpressionEvaluator(ValueExpression expression, RowKeySet[] out)
+ {
+ _out = out;
+ _expression = expression;
+ }
+ public void invokeContextCallback(FacesContext context,
+ UIComponent target)
+ {
+ _out[0] = (RowKeySet)_expression.getValue(context.getELContext());
+ }
+
+ private final RowKeySet[] _out;
+ private final ValueExpression _expression;
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ private final String _clientId;
+}
Propchange: myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/change/RowKeySetAttributeChange.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java?rev=1044172&r1=1044171&r2=1044172&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java (original)
+++ myfaces/trinidad/branches/1.2.12.3-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXComponentBase.java Thu Dec 9 23:50:48 2010
@@ -56,10 +56,12 @@ import org.apache.myfaces.trinidad.bean.
import org.apache.myfaces.trinidad.bean.util.StateUtils;
import org.apache.myfaces.trinidad.bean.util.ValueMap;
import org.apache.myfaces.trinidad.change.AttributeComponentChange;
+import org.apache.myfaces.trinidad.change.RowKeySetAttributeChange;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.event.AttributeChangeEvent;
import org.apache.myfaces.trinidad.event.AttributeChangeListener;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.render.ExtendedRenderer;
import org.apache.myfaces.trinidad.render.LifecycleRenderer;
import org.apache.myfaces.trinidad.util.ThreadLocalUtils;
@@ -1087,8 +1089,17 @@ abstract public class UIXComponentBase e
String attributeName,
Object attributeValue)
{
- AttributeComponentChange aa =
- new AttributeComponentChange(attributeName, attributeValue);
+ AttributeComponentChange aa;
+
+ if (attributeValue instanceof RowKeySet)
+ {
+ aa = new RowKeySetAttributeChange(getClientId(), attributeName, attributeValue);
+ }
+ else
+ {
+ aa = new AttributeComponentChange(attributeName, attributeValue);
+ }
+
RequestContext adfContext = RequestContext.getCurrentInstance();
adfContext.getChangeManager().addComponentChange(getFacesContext(), this, aa);
}