You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/04/02 21:43:32 UTC
svn commit: r930359 - in
/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad:
component/UIXCollection.java component/ValueMap.java
render/ClientRowKeyManager.java
Author: arobinson74
Date: Fri Apr 2 19:43:32 2010
New Revision: 930359
URL: http://svn.apache.org/viewvc?rev=930359&view=rev
Log:
Patch from Kamran
TRINIDAD-1771
Modified:
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ValueMap.java
myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/ClientRowKeyManager.java
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java?rev=930359&r1=930358&r2=930359&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXCollection.java Fri Apr 2 19:43:32 2010
@@ -1849,9 +1849,6 @@ public abstract class UIXCollection exte
@Override
public Object getRowKey(FacesContext context, UIComponent component, String clientRowKey)
{
- if (_isOptimizedKey(clientRowKey))
- return clientRowKey;
-
ValueMap<Object,String> currencyCache = _currencyCache;
Object rowkey = currencyCache.getKey(clientRowKey);
return rowkey;
@@ -1871,20 +1868,6 @@ public abstract class UIXCollection exte
if (key == null)
{
// we don't have a string-key, so create a new one.
-
- // first check to see if the rowkey itself can be used as the string-key:
- if (rowKey instanceof String)
- {
- // TODO: make sure that this string is suitable for use as
- // NamingContainer ids:
- key = rowKey.toString();
- if (_isOptimizedKey(key))
- {
- // no need to add to the token map:
- return key;
- }
- }
-
key = _createToken(currencyCache);
if (_LOG.isFiner())
@@ -1896,17 +1879,26 @@ public abstract class UIXCollection exte
return key;
}
- private static boolean _isOptimizedKey(String key)
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean replaceRowKey(FacesContext context, UIComponent component, Object oldRowKey, Object newRowKey)
{
- // if a key could be a number, then it might conflict with our
- // internal representation of tokens. Therefore, if a key could be
- // a number, then use the token cache.
- // if there is no way this key can be a number, then it can
- // be treated as an optimized key and can bypass the token cache
- // system:
- return ((key.length() > 0) && (!Character.isDigit(key.charAt(0))));
+ assert oldRowKey != null && newRowKey != null;
+
+ ValueMap<Object,String> currencyCache = _currencyCache;
+ String key = currencyCache.remove(oldRowKey);
+ // check to see if we already have a string key:
+ if (key != null)
+ {
+ currencyCache.put(newRowKey, key);
+ }
+ return key != null;
}
+
+
private static String _createToken(ValueMap<Object,String> currencyCache)
{
String key = String.valueOf(currencyCache.size());
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ValueMap.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ValueMap.java?rev=930359&r1=930358&r2=930359&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ValueMap.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/ValueMap.java Fri Apr 2 19:43:32 2010
@@ -79,6 +79,25 @@ final class ValueMap<K, V> extends Abstr
return old;
}
+ /**
+ * Removes the mapping for the specified key. Also
+ * removes the corresponding value mapping.
+ * @param key
+ * @return
+ */
+ @Override
+ public V remove(Object key)
+ {
+ V value = _cache.remove(key);
+
+ if (value != null)
+ {
+ K oldKey = _valueMap.remove(value);
+ assert oldKey != null : "missing key in value map for value "+value;
+ }
+ return value;
+ }
+
@Override
public void clear()
{
Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/ClientRowKeyManager.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/ClientRowKeyManager.java?rev=930359&r1=930358&r2=930359&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/ClientRowKeyManager.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/ClientRowKeyManager.java Fri Apr 2 19:43:32 2010
@@ -53,5 +53,21 @@ public abstract class ClientRowKeyManage
*/
public abstract Object getRowKey(FacesContext context, UIComponent component, String clientRowKey);
+
+ /**
+ * Replaces an old row key with a new key if the old row key exists. If the old row key is successfully replaced,
+ * the new row key will be mapped to the existing client row key.
+ * @param context
+ * @param component
+ * @param oldRowKey row key to replace (may not exist)
+ * @param newRowKey new row key
+ * @return <code>true</code> if old row key existed and was replaced, <code>false</code> otherwise
+ */
+ public boolean replaceRowKey(FacesContext context, UIComponent component, Object oldRowKey, Object newRowKey)
+ {
+ // default implementation to maintain backwards compatibility
+ return false;
+ }
+
private static final long serialVersionUID = 1L;
}