You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ja...@apache.org on 2010/05/04 16:06:15 UTC
svn commit: r940862 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
Author: jakobk
Date: Tue May 4 14:06:15 2010
New Revision: 940862
URL: http://svn.apache.org/viewvc?rev=940862&view=rev
Log:
MYFACES-2695 Save and restore scope values and current count when temporarily changing the current index of UIRepeat
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java?rev=940862&r1=940861&r2=940862&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java Tue May 4 14:06:15 2010
@@ -357,6 +357,7 @@ public class UIRepeat extends UIComponen
if (_origValue != null)
{
attrs.put(_var, _origValue);
+ _origValue = null;
}
else
{
@@ -369,6 +370,7 @@ public class UIRepeat extends UIComponen
if (_origVarStatus != null)
{
attrs.put(_varStatus, _origVarStatus);
+ _origVarStatus = null;
}
else
{
@@ -453,7 +455,7 @@ public class UIRepeat extends UIComponen
_saveChildState(faces, itr.next());
}
}
-
+
private void _setIndex(int index)
{
// save child state
@@ -482,6 +484,16 @@ public class UIRepeat extends UIComponen
_restoreChildState();
}
+ /**
+ * Calculates the count value for the given index.
+ * @param index
+ * @return
+ */
+ private int _calculateCountForIndex(int index)
+ {
+ return (index - getOffset()) / getStep();
+ }
+
private void _validateAttributes () throws FacesException {
int begin = getOffset();
int end = getDataModel().getRowCount();
@@ -649,7 +661,7 @@ public class UIRepeat extends UIComponen
if (invokeIndex != -1)
{
// calculate count for RepeatStatus
- _count = (invokeIndex - getOffset()) / getStep();
+ _count = _calculateCountForIndex(invokeIndex);
}
_setIndex(invokeIndex);
@@ -936,10 +948,20 @@ public class UIRepeat extends UIComponen
public void processListener(FacesListener listener)
{
UIRepeat owner = (UIRepeat) getComponent();
- int prevIndex = owner._index;
+
+ // safe the current index, count aside
+ final int prevIndex = owner._index;
+ final int prevCount = owner._count;
+
try
{
- owner._setIndex(_index);
+ owner._captureScopeValues();
+ if (this._index != -1)
+ {
+ // calculate count for RepeatStatus
+ _count = _calculateCountForIndex(this._index);
+ }
+ owner._setIndex(this._index);
if (owner._isIndexAvailable())
{
_target.processListener(listener);
@@ -947,7 +969,10 @@ public class UIRepeat extends UIComponen
}
finally
{
+ // restore the previous count, index and scope values
+ owner._count = prevCount;
owner._setIndex(prevIndex);
+ owner._restoreScopeValues();
}
}
@@ -970,9 +995,19 @@ public class UIRepeat extends UIComponen
{
IndexedEvent idxEvent = (IndexedEvent) event;
_resetDataModel();
- int prevIndex = _index;
+
+ // safe the current index, count aside
+ final int prevIndex = _index;
+ final int prevCount = _count;
+
try
{
+ _captureScopeValues();
+ if (idxEvent.getIndex() != -1)
+ {
+ // calculate count for RepeatStatus
+ _count = _calculateCountForIndex(idxEvent.getIndex());
+ }
_setIndex(idxEvent.getIndex());
if (_isIndexAvailable())
{
@@ -982,7 +1017,10 @@ public class UIRepeat extends UIComponen
}
finally
{
+ // restore the previous count, index and scope values
+ _count = prevCount;
_setIndex(prevIndex);
+ _restoreScopeValues();
}
}
else