You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/03/21 14:53:10 UTC
svn commit: r1827414 - in /myfaces/core/branches/2.3.x: ./
impl/src/main/java/org/apache/myfaces/view/facelets/component/
impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/
impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/
Author: tandraschko
Date: Wed Mar 21 14:53:10 2018
New Revision: 1827414
URL: http://svn.apache.org/viewvc?rev=1827414&view=rev
Log:
MYFACES-4203 - UIRepeat begin+end doesn't work correctly
Added:
myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatBeginEnd.xhtml
- copied, changed from r1827413, myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeat.xhtml
Modified:
myfaces/core/branches/2.3.x/ (props changed)
myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java
Propchange: myfaces/core/branches/2.3.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Mar 21 14:53:10 2018
@@ -2,5 +2,5 @@
/myfaces/core/branches/2.0.x:1098582-1124475
/myfaces/core/branches/2.1.x:1469145-1470662,1470740,1470769,1481616,1486734,1487195,1488257,1488269,1491839,1505866,1518438,1518452,1518455,1523314,1523353,1523365,1523370,1523379,1525533,1525535,1525863,1526422,1531547,1532548,1532563,1532588,1532605,1532836,1533085,1533114,1533175,1533192,1533230,1533291,1533536,1534237
/myfaces/core/branches/2.1.x-client-window:1396979-1406260,1410177-1410189,1410207-1420939,1420950-1421674,1433517
-/myfaces/core/trunk:1085607-1098581,1368943-1368953,1377776-1380084,1383166,1383168,1384981,1384983,1386916,1386944,1389919,1390212,1392355,1393567,1393891,1395401,1395406,1395409,1395974,1397444,1398700,1398769,1398929,1399817,1400150,1401352,1402825,1402849,1403894,1405217,1406527,1406532,1408903,1409426,1409468,1409476,1410155,1410171,1410540,1410553,1410652,1412781,1412831,1412932,1417719,1418586,1418589,1421641-1421655,1423194-1432818,1433542,1448215,1448221,1449029,1449777,1451580,1455392,1461879,1461883,1461890,1461893,1461916,1462113,1467143
+/myfaces/core/trunk:1085607-1098581,1368943-1368953,1377776-1380084,1383166,1383168,1384981,1384983,1386916,1386944,1389919,1390212,1392355,1393567,1393891,1395401,1395406,1395409,1395974,1397444,1398700,1398769,1398929,1399817,1400150,1401352,1402825,1402849,1403894,1405217,1406527,1406532,1408903,1409426,1409468,1409476,1410155,1410171,1410540,1410553,1410652,1412781,1412831,1412932,1417719,1418586,1418589,1421641-1421655,1423194-1432818,1433542,1448215,1448221,1449029,1449777,1451580,1455392,1461879,1461883,1461890,1461893,1461916,1462113,1467143,1824490
/myfaces/core/trunk_1.2.x:691297-695050,698037-743106,752296-779418,779422-792656
Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java?rev=1827414&r1=1827413&r2=1827414&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java Wed Mar 21 14:53:10 2018
@@ -73,8 +73,6 @@ public class UIRepeat extends UIComponen
private static final String STRING_BUILDER_KEY
= UIRepeat.class.getName() + ".SHARED_STRING_BUILDER";
-
- //private static final String SKIP_ITERATION_HINT = "javax.faces.visit.SKIP_ITERATION";
private final static DataModel<?> EMPTY_MODEL = new ListDataModel<Object>(Collections.emptyList());
@@ -335,7 +333,7 @@ public class UIRepeat extends UIComponen
begin = getOffset();
}
- return new RepeatStatus(_count == 0, _index + getStep() >= getDataModel().getRowCount(),
+ return new RepeatStatus(_count == 0, _index + getStep() >= getRowCount(),
_count, _index, begin, _end, getStep());
}
@@ -356,7 +354,7 @@ public class UIRepeat extends UIComponen
private boolean _isIndexAvailable()
{
- return getDataModel().isRowAvailable();
+ return getDataModel() == EMPTY_MODEL || getDataModel().isRowAvailable();
}
private void _restoreScopeValues()
@@ -732,7 +730,14 @@ public class UIRepeat extends UIComponen
*/
public int getRowCount()
{
- return getDataModel().getRowCount();
+ if (getValue() == null) // empty model
+ {
+ return (getEnd() - getBegin())/(getStep() <= 0 ? 1 : getStep());
+ }
+ else
+ {
+ return getDataModel().getRowCount();
+ }
}
/**
@@ -802,10 +807,17 @@ public class UIRepeat extends UIComponen
if (_index != -1)
{
String var = getVar();
- if (var != null && localModel.isRowAvailable())
+ boolean emptyModel = getDataModel() == EMPTY_MODEL;
+ if (var != null && (emptyModel || localModel.isRowAvailable()))
{
- getFacesContext().getExternalContext().getRequestMap()
- .put(var, localModel.getRowData());
+ if (emptyModel)
+ {
+ getFacesContext().getExternalContext().getRequestMap().put(var, _index);
+ }
+ else
+ {
+ getFacesContext().getExternalContext().getRequestMap().put(var, localModel.getRowData());
+ }
}
String varStatus = getVarStatus();
if (varStatus != null)
@@ -873,10 +885,11 @@ public class UIRepeat extends UIComponen
private void _validateAttributes() throws FacesException
{
+ boolean emptyModel = getDataModel() == EMPTY_MODEL;
int begin = getBegin();
int end = getEnd();
int size = getSize();
- int count = getDataModel().getRowCount();
+ int count = getRowCount();
int offset = getOffset();
if (begin == -1)
{
@@ -888,7 +901,12 @@ public class UIRepeat extends UIComponen
if (end == -1 && size == -1)
{
- if (begin == -1)
+ if (emptyModel && end == -1)
+ {
+ throw new FacesException("on empty models, you must define begin and " +
+ "end");
+ }
+ else if (begin == -1)
{
end = getDataModel().getRowCount();
}
@@ -899,7 +917,8 @@ public class UIRepeat extends UIComponen
}
int step = getStep();
- boolean sizeIsEnd = false;
+ boolean sizeIsEnd = emptyModel;
+ boolean countdown = emptyModel && end < begin;
if (size == -1)
{
@@ -910,11 +929,26 @@ public class UIRepeat extends UIComponen
}
else
{
- size = end - begin + 1;
+ size = countdown ? (begin - end + 1)/step : (end - begin + 1)/step;
}
}
+
+ step = countdown && step > 0 ? -step : step;
- if (end >= 0)
+ if (emptyModel)
+ {
+ if (step > 0 && (end < begin))
+ {
+ throw new FacesException("on empty models, end cannot be less than begin " +
+ "when the step is positive");
+ }
+ else if (step < 0 && (end > begin))
+ {
+ throw new FacesException("on empty models, end cannot be greater than begin " +
+ "when the step is negative");
+ }
+ }
+ else if (end >= 0)
{
if (size < 0)
{
@@ -947,23 +981,23 @@ public class UIRepeat extends UIComponen
"than collection size");
}
}
- if ((begin >= 0) && (begin > end))
+ if (!emptyModel && (begin >= 0) && (begin > end))
{
throw new FacesException("begin cannot be greater " +
"end");
}
- if ((size > -1) && (offset > end))
+ if (!emptyModel && (size > -1) && (offset > end))
{
throw new FacesException("iteration offset cannot be greater " +
"than collection size");
}
- if (step == -1)
+ if (!emptyModel && step == -1)
{
setStep(1);
}
- if (step < 0)
+ if (!emptyModel && step < 0)
{
throw new FacesException("iteration step size cannot be less " +
"than zero");
@@ -975,7 +1009,7 @@ public class UIRepeat extends UIComponen
"to zero");
}
-
+ setStep(step);
_end = end;
}
@@ -1027,7 +1061,7 @@ public class UIRepeat extends UIComponen
_setIndex(i);
- while (i <= end && _isIndexAvailable())
+ while (((step > 0 && i <= end) || (step < 0 && i >= end)) && _isIndexAvailable())
{
if (PhaseId.RENDER_RESPONSE.equals(phase) && renderer != null)
Modified: myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java?rev=1827414&r1=1827413&r2=1827414&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java (original)
+++ myfaces/core/branches/2.3.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java Wed Mar 21 14:53:10 2018
@@ -799,4 +799,33 @@ public class RepeatTestCase extends Face
//System.out.println(fw);
}
+
+
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testInvokeOnComponentBeginEnd() throws IOException
+ {
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "testUIRepeatBeginEnd.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat");
+ Assert.assertNotNull(repeat);
+
+ FastWriter fw = new FastWriter();
+ ResponseWriter rw = facesContext.getResponseWriter();
+ rw = rw.cloneWithWriter(fw);
+ facesContext.setResponseWriter(rw);
+
+ repeat.encodeAll(facesContext);
+
+ String content = fw.toString();
+
+ Assert.assertTrue(content.contains("Hello 1"));
+ Assert.assertTrue(content.contains("Hello 2"));
+ Assert.assertTrue(content.contains("Hello 3"));
+
+ Assert.assertFalse(content.contains("Hello 0"));
+ Assert.assertFalse(content.contains("Hello 4"));
+ }
}
Copied: myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatBeginEnd.xhtml (from r1827413, myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeat.xhtml)
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatBeginEnd.xhtml?p2=myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatBeginEnd.xhtml&p1=myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeat.xhtml&r1=1827413&r2=1827414&rev=1827414&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeat.xhtml (original)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatBeginEnd.xhtml Wed Mar 21 14:53:10 2018
@@ -20,8 +20,8 @@
</head>
<body>
<h:form id="form">
- <ui:repeat id="repeat" value="#{repeatValues}" var="row" varStatus="status">
- <h:outputText id="outputText" value="#{row}" />
+ <ui:repeat id="repeat" begin="1" end="3" var="i">
+ <h:outputText id="outputText" value="Hello #{i}" />
</ui:repeat>
</h:form>
</body>