You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by mi...@apache.org on 2005/09/20 23:31:03 UTC
svn commit: r290571 - in
/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components:
For.jwc ForBean.java Foreach.java
Author: mindbridge
Date: Tue Sep 20 14:30:56 2005
New Revision: 290571
URL: http://svn.apache.org/viewcvs?rev=290571&view=rev
Log:
[TAPESTRY-654] Removed caching of 'source' and 'fullSource'
in Foreach and For. Also ensured that all variables in For
are local and no properties are used. A loop within a loop
or recursive loops now work.
Modified:
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/For.jwc
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/ForBean.java
jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/Foreach.java
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/For.jwc
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/For.jwc?rev=290571&r1=290570&r2=290571&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/For.jwc (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/For.jwc Tue Sep 20 14:30:56 2005
@@ -103,10 +103,11 @@
<parameter name="match" default-value="true">
<description>
- Only active in a form. This parameter allows the matching of the squeezed
- representation of the values with that of the values in 'source'. It guarantees
- that the values iterated upon are physically identical to the ones provided.
- The method is often slower than simple unsqueezing, but it eliminates a number
+ Only active in a form. This parameter allows the matching of the string
+ representation of the values stored in the hidden fields with that
+ of the values in 'source'. It guarantees that the values iterated upon are
+ physically identical to the ones provided.
+ The method is sometimes slower than simple unsqueezing, but it eliminates a number
of potential pitfalls. Please disable with caution.
</description>
</parameter>
@@ -118,8 +119,6 @@
and cause exceptions as a result. Please use with caution.
</description>
</parameter>
-
- <property name="repToValueMap" initial-value="new java.util.HashMap()"/>
<inject property="dataSqueezer" object="service:tapestry.data.DataSqueezer"/>
<inject property="valueConverter" object="service:tapestry.coerce.ValueConverter"/>
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/ForBean.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/ForBean.java?rev=290571&r1=290570&r2=290571&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/ForBean.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/ForBean.java Tue Sep 20 14:30:56 2005
@@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -43,8 +44,6 @@
private final RepSource KEY_EXPRESSION_REP_SOURCE = new KeyExpressionRepSource();
// parameters
- public abstract Object getSource();
- public abstract Object getFullSource();
public abstract String getElement();
public abstract String getKeyExpression();
public abstract IPrimaryKeyConverter getConverter();
@@ -52,16 +51,6 @@
public abstract boolean getMatch();
public abstract boolean getVolatile();
- // properties
- public abstract Iterator getSourceIterator();
- public abstract void setSourceIterator(Iterator sourceIterator);
-
- public abstract Iterator getFullSourceIterator();
- public abstract void setFullSourceIterator(Iterator fullSourceIterator);
-
- public abstract Map getRepToValueMap();
- public abstract void setRepToValueMap(Map repToValue);
-
// injects
public abstract DataSqueezer getDataSqueezer();
public abstract ValueConverter getValueConverter();
@@ -80,10 +69,6 @@
**/
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
- // Clear the cache between rewind and render.
- // This allows the value of 'source' to be changed by the form listeners.
- setSourceIterator(null);
-
// form may be null if component is not located in a form
IForm form = (IForm) cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE);
@@ -238,7 +223,7 @@
**/
private Iterator getData(IRequestCycle cycle, IForm form) {
if (form == null || getVolatile())
- return getSourceIteratorValue();
+ return evaluateSourceIterator();
String name = form.getElementId(this);
if (cycle.isRewinding())
@@ -262,11 +247,15 @@
updatePrimaryKeysParameter(stringReps);
+ Iterator sourceIterator = evaluateSourceIterator();
+ Iterator fullSourceIterator = evaluateFullSourceIterator();
+ Map repToValueMap = new HashMap();
+
int valueCount = stringReps.length;
List values = new ArrayList(valueCount);
for (int i = 0; i < valueCount; i++) {
String rep = stringReps[i];
- Object value = getValueFromStringRep(rep);
+ Object value = getValueFromStringRep(sourceIterator, fullSourceIterator, repToValueMap, rep);
values.add(value);
}
@@ -286,7 +275,7 @@
{
List values = new ArrayList();
- Iterator it = getSourceIteratorValue();
+ Iterator it = evaluateSourceIterator();
while (it.hasNext()) {
Object value = it.next();
values.add(value);
@@ -385,7 +374,8 @@
* @param rep the string representation for which a value should be returned
* @return the value that corresponds to the provided string representation
*/
- protected Object getValueFromStringRep(String rep) {
+ protected Object getValueFromStringRep(Iterator sourceIterator, Iterator fullSourceIterator,
+ Map repToValueMap, String rep) {
Object value = null;
DataSqueezer squeezer = getDataSqueezer();
@@ -396,7 +386,7 @@
// If required, find a value with an equivalent string representation and return it
boolean match = getMatch();
if (match) {
- value = findValueWithStringRep(rep, COMPLETE_REP_SOURCE);
+ value = findValueWithStringRep(sourceIterator, fullSourceIterator, repToValueMap, rep, COMPLETE_REP_SOURCE);
if (value != null)
return value;
}
@@ -414,7 +404,7 @@
case DESC_PRIMARY_KEY:
// Perform keyExpression match if not already attempted
if (!match && getKeyExpression() != null)
- value = findValueWithStringRep(rep, KEY_EXPRESSION_REP_SOURCE);
+ value = findValueWithStringRep(sourceIterator, fullSourceIterator, repToValueMap, rep, KEY_EXPRESSION_REP_SOURCE);
// If 'converter' is defined, try to perform conversion from primary key to value
if (value == null) {
@@ -445,20 +435,17 @@
* @return the value in 'source' or 'fullSource' that corresponds
* to the provided string representation
*/
- protected Object findValueWithStringRep(String rep, RepSource repSource) {
- Map repToValueMap = getRepToValueMap();
-
+ protected Object findValueWithStringRep(Iterator sourceIterator, Iterator fullSourceIterator,
+ Map repToValueMap, String rep, RepSource repSource) {
Object value = repToValueMap.get(rep);
if (value != null)
return value;
- Iterator it = getSourceIteratorValue();
- value = findValueWithStringRepInIterator(rep, repSource, it);
+ value = findValueWithStringRepInIterator(sourceIterator, repToValueMap, rep, repSource);
if (value != null)
return value;
- it = getFullSourceIteratorValue();
- value = findValueWithStringRepInIterator(rep, repSource, it);
+ value = findValueWithStringRepInIterator(fullSourceIterator, repToValueMap, rep, repSource);
return value;
}
@@ -475,9 +462,7 @@
* @return the value in the provided collection that corresponds
* to the required string representation
*/
- protected Object findValueWithStringRepInIterator(String rep, RepSource repSource, Iterator it) {
- Map repToValueMap = getRepToValueMap();
-
+ protected Object findValueWithStringRepInIterator(Iterator it, Map repToValueMap, String rep, RepSource repSource) {
while (it.hasNext()) {
Object sourceValue = it.next();
if (sourceValue == null)
@@ -492,41 +477,49 @@
return null;
}
-
+
/**
- * Returns the cached 'source' iterator. The value is initialized
- * with the iterator provided by the 'source' parameter
+ * Returns a new iterator of the values in 'source'.
*
- * @return the cached 'source' iterator
+ * @return the 'source' iterator
*/
- protected Iterator getSourceIteratorValue()
+ protected Iterator evaluateSourceIterator()
{
- Iterator it = getSourceIterator();
- if (it == null) {
- it = (Iterator) getValueConverter().coerceValue(getSource(), Iterator.class);
- if (it == null)
- it = Collections.EMPTY_LIST.iterator();
- setSourceIterator(it);
- }
+ Iterator it = null;
+ Object source = null;
+
+ IBinding sourceBinding = getBinding("source");
+ if (sourceBinding != null)
+ source = sourceBinding.getObject();
+
+ if (source != null)
+ it = (Iterator) getValueConverter().coerceValue(source, Iterator.class);
+
+ if (it == null)
+ it = Collections.EMPTY_LIST.iterator();
return it;
}
/**
- * Returns the cached 'fullSource' iterator. The value is initialized
- * with the iterator provided by the 'fullSource' parameter
+ * Returns a new iterator of the values in 'fullSource'.
*
- * @return the cached 'fullSource' iterator
+ * @return the 'fullSource' iterator
*/
- protected Iterator getFullSourceIteratorValue()
+ protected Iterator evaluateFullSourceIterator()
{
- Iterator it = getFullSourceIterator();
- if (it == null) {
- it = (Iterator) getValueConverter().coerceValue(getFullSource(), Iterator.class);
- if (it == null)
- it = Collections.EMPTY_LIST.iterator();
- setFullSourceIterator(it);
- }
+ Iterator it = null;
+ Object fullSource = null;
+
+ IBinding fullSourceBinding = getBinding("fullSource");
+ if (fullSourceBinding != null)
+ fullSource = fullSourceBinding.getObject();
+
+ if (fullSource != null)
+ it = (Iterator) getValueConverter().coerceValue(fullSource, Iterator.class);
+
+ if (it == null)
+ it = Collections.EMPTY_LIST.iterator();
return it;
}
@@ -568,12 +561,11 @@
public String getClientId()
{
- // TODO Auto-generated method stub
return null;
}
+
public String getDisplayName()
{
- // TODO Auto-generated method stub
return null;
}
Modified: jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/Foreach.java
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/Foreach.java?rev=290571&r1=290570&r2=290571&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/Foreach.java (original)
+++ jakarta/tapestry/trunk/framework/src/java/org/apache/tapestry/components/Foreach.java Tue Sep 20 14:30:56 2005
@@ -17,6 +17,7 @@
import java.util.Iterator;
import org.apache.tapestry.AbstractComponent;
+import org.apache.tapestry.IBinding;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.Tapestry;
@@ -49,7 +50,11 @@
protected Iterator getSourceData()
{
- Object source = getSource();
+ Object source = null;
+
+ IBinding sourceBinding = getBinding("source");
+ if (sourceBinding != null)
+ source = sourceBinding.getObject();
if (source == null)
return null;
@@ -131,10 +136,6 @@
return _value;
}
- public abstract String getElement();
-
- public abstract Object getSource();
-
/**
* The index number, within the {@link #getSource() source}, of the the current value.
*
@@ -150,6 +151,8 @@
return _index;
}
+
+ public abstract String getElement();
/** @since 4.0 */
public abstract void setIndexParameter(int value);
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org