You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2013/09/14 22:31:47 UTC
svn commit: r1523314 - in /myfaces/core/branches/2.1.x/impl/src:
main/java/org/apache/myfaces/view/facelets/component/
test/java/org/apache/myfaces/view/facelets/tag/ui/
test/resources/org/apache/myfaces/view/facelets/tag/ui/
Author: lu4242
Date: Sat Sep 14 20:31:46 2013
New Revision: 1523314
URL: http://svn.apache.org/r1523314
Log:
MYFACES-3773 ui:repeat with offset and size does not behave as expected
Modified:
myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
myfaces/core/branches/2.1.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java
myfaces/core/branches/2.1.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml
Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java?rev=1523314&r1=1523313&r2=1523314&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/view/facelets/component/UIRepeat.java Sat Sep 14 20:31:46 2013
@@ -901,7 +901,7 @@ public class UIRepeat extends UIComponen
_count = 0;
_setIndex(i);
- while (i <= end && _isIndexAvailable())
+ while (i < end && _isIndexAvailable())
{
if (PhaseId.RENDER_RESPONSE.equals(phase) && renderer != null)
@@ -1176,7 +1176,7 @@ public class UIRepeat extends UIComponen
_count = 0;
_setIndex(i);
- while (i <= end && _isIndexAvailable())
+ while (i < end && _isIndexAvailable())
{
for (int j = 0, childCount = getChildCount(); j < childCount; j++)
{
Modified: myfaces/core/branches/2.1.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java?rev=1523314&r1=1523313&r2=1523314&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/test/java/org/apache/myfaces/view/facelets/tag/ui/RepeatTestCase.java Sat Sep 14 20:31:46 2013
@@ -25,6 +25,7 @@ import java.util.List;
import javax.el.ELContext;
import javax.el.ELException;
import javax.el.ValueExpression;
+import javax.faces.FacesException;
import javax.faces.component.ContextCallback;
import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
@@ -65,7 +66,25 @@ public class RepeatTestCase extends Face
rw = rw.cloneWithWriter(fw);
facesContext.setResponseWriter(rw);
root.encodeAll(facesContext);
- //System.out.println(fw);
+ String content = fw.toString();
+
+ int hrIndex = content.indexOf("<dt>HR</dt>");
+ Assert.assertNotSame(-1, hrIndex);
+ int rdIndex = content.indexOf("<dt>RD</dt>", hrIndex);
+ Assert.assertNotSame(-1, rdIndex);
+
+ int empIndex1 = content.indexOf(
+ "<dd class=\"3\">Ellen, Sue</dd><dd class=\"4\">Scooner, Mary</dd>", hrIndex);
+ Assert.assertNotSame(-1, empIndex1);
+ int empIndex2 = content.indexOf(
+ "<dd class=\"6\">Burns, Ed</dd><dd class=\"7\">Lubke, Ryan</dd><dd class=\"8\">Kitain, Roger</dd>",
+ rdIndex);
+ Assert.assertNotSame(-1, empIndex2);
+
+ int hrIndex2 = content.indexOf("<li class=\"HR\">HR</li>");
+ Assert.assertNotSame(-1, hrIndex2);
+ int rdIndex2 = content.indexOf("<li class=\"RD\">RD</li>", hrIndex2);
+ Assert.assertNotSame(-1, rdIndex2);
}
/**
@@ -323,7 +342,6 @@ public class RepeatTestCase extends Face
}
-
@Test
public void testRepeatOffset() throws Exception
{
@@ -333,15 +351,224 @@ public class RepeatTestCase extends Face
UIViewRoot root = facesContext.getViewRoot();
vdl.buildView(facesContext, root, "ui_repeat_offset.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);
- root.encodeAll(facesContext);
- //System.out.println(fw);
+
+ repeat.encodeAll(facesContext);
+ String content = fw.toString();
+
+ // offset="2" size="1" should render only 1 row
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertEquals(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2");
+ Assert.assertEquals(-1, itemIndex2);
+
+ String item1 = "B3";
+ int itemIndex3 = content.indexOf(item1);
+ Assert.assertNotSame(-1, itemIndex3);
+ String item2 = "B4";
+ // the second item should not be there
+ Assert.assertEquals(-1, content.indexOf(item2, itemIndex1+2));
}
@Test
+ public void testRepeatOffset_0() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat0");
+ 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();
+
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertNotSame(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2");
+ Assert.assertNotSame(-1, itemIndex2);
+ int itemIndex3 = content.indexOf("B3");
+ Assert.assertEquals(-1, itemIndex3);
+ }
+
+ @Test
+ public void testRepeatOffset_0_7() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat0_7");
+ 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();
+
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertNotSame(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2", itemIndex1);
+ Assert.assertNotSame(-1, itemIndex2);
+ int itemIndex3 = content.indexOf("B3", itemIndex2);
+ Assert.assertNotSame(-1, itemIndex3);
+ int itemIndex4 = content.indexOf("B4", itemIndex3);
+ Assert.assertNotSame(-1, itemIndex4);
+ int itemIndex5 = content.indexOf("B5", itemIndex4);
+ Assert.assertNotSame(-1, itemIndex5);
+ int itemIndex6 = content.indexOf("B6", itemIndex5);
+ Assert.assertNotSame(-1, itemIndex6);
+ int itemIndex7 = content.indexOf("B7", itemIndex6);
+ Assert.assertNotSame(-1, itemIndex7);
+ }
+
+ @Test
+ public void testRepeatOffset_0_8() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat0_8");
+ Assert.assertNotNull(repeat);
+
+ FastWriter fw = new FastWriter();
+ ResponseWriter rw = facesContext.getResponseWriter();
+ rw = rw.cloneWithWriter(fw);
+ facesContext.setResponseWriter(rw);
+
+ try
+ {
+ repeat.encodeAll(facesContext);
+ Assert.fail();
+ }
+ catch(FacesException e)
+ {
+ // size cannot be greater than collection size
+ }
+ }
+
+ @Test
+ public void testRepeatOffset_1() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat1");
+ 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();
+
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertEquals(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2");
+ Assert.assertNotSame(-1, itemIndex2);
+ int itemIndex3 = content.indexOf("B3", itemIndex2);
+ Assert.assertNotSame(-1, itemIndex3);
+ int itemIndex4 = content.indexOf("B4", itemIndex3);
+ Assert.assertNotSame(-1, itemIndex4);
+ int itemIndex5 = content.indexOf("B5", itemIndex4);
+ Assert.assertEquals(-1, itemIndex5);
+ }
+
+ @Test
+ public void testRepeatOffset_1_7() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat1_7");
+ 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();
+
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertEquals(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2");
+ Assert.assertNotSame(-1, itemIndex2);
+ int itemIndex3 = content.indexOf("B3", itemIndex2);
+ Assert.assertNotSame(-1, itemIndex3);
+ int itemIndex4 = content.indexOf("B4", itemIndex3);
+ Assert.assertNotSame(-1, itemIndex4);
+ int itemIndex5 = content.indexOf("B5", itemIndex4);
+ Assert.assertNotSame(-1, itemIndex5);
+ int itemIndex6 = content.indexOf("B6", itemIndex5);
+ Assert.assertNotSame(-1, itemIndex6);
+ int itemIndex7 = content.indexOf("B7", itemIndex6);
+ Assert.assertNotSame(-1, itemIndex7);
+ }
+
+ @Test
+ public void testRepeatOffset_1_8() throws Exception
+ {
+ final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
+ facesContext.getExternalContext().getRequestMap().put("repeatValues", repeatValues);
+
+ UIViewRoot root = facesContext.getViewRoot();
+ vdl.buildView(facesContext, root, "ui_repeat_offset.xhtml");
+
+ UIRepeat repeat = (UIRepeat) root.findComponent("form:repeat1_8");
+ Assert.assertNotNull(repeat);
+
+ FastWriter fw = new FastWriter();
+ ResponseWriter rw = facesContext.getResponseWriter();
+ rw = rw.cloneWithWriter(fw);
+ facesContext.setResponseWriter(rw);
+
+ try
+ {
+ repeat.encodeAll(facesContext);
+ Assert.fail();
+ }
+ catch(FacesException e)
+ {
+ // size cannot be greater than collection size
+ }
+ }
+
+ @Test
public void testRepeatOffset2() throws Exception
{
final String[] repeatValues = new String[] {"B1", "B2", "B3", "B4", "B5", "B6", "B7"};
@@ -350,11 +577,33 @@ public class RepeatTestCase extends Face
UIViewRoot root = facesContext.getViewRoot();
vdl.buildView(facesContext, root, "ui_repeat_offset2.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);
- root.encodeAll(facesContext);
+
+ repeat.encodeAll(facesContext);
+
+ String content = fw.toString();
+
+ int itemIndex1 = content.indexOf("B1");
+ Assert.assertEquals(-1, itemIndex1);
+ int itemIndex2 = content.indexOf("B2");
+ Assert.assertEquals(-1, itemIndex2);
+ int itemIndex3 = content.indexOf("B3");
+ Assert.assertNotSame(-1, itemIndex3);
+ int itemIndex4 = content.indexOf("B4", itemIndex3);
+ Assert.assertNotSame(-1, itemIndex4);
+ int itemIndex5 = content.indexOf("B5", itemIndex4);
+ Assert.assertNotSame(-1, itemIndex5);
+ int itemIndex6 = content.indexOf("B6", itemIndex5);
+ Assert.assertNotSame(-1, itemIndex6);
+ int itemIndex7 = content.indexOf("B7", itemIndex6);
+ Assert.assertNotSame(-1, itemIndex7);
+
//System.out.println(fw);
}
}
Modified: myfaces/core/branches/2.1.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml?rev=1523314&r1=1523313&r2=1523314&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml (original)
+++ myfaces/core/branches/2.1.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml Sat Sep 14 20:31:46 2013
@@ -23,6 +23,24 @@
<ui:repeat id="repeat" value="#{repeatValues}" var="row" offset="2" size="1" >
<h:outputText id="outputText" value="#{row}" />
</ui:repeat>
+ <ui:repeat id="repeat0" value="#{repeatValues}" var="row" offset="0" size="2" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
+ <ui:repeat id="repeat0_7" value="#{repeatValues}" var="row" offset="0" size="7" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
+ <ui:repeat id="repeat0_8" value="#{repeatValues}" var="row" offset="0" size="8" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
+ <ui:repeat id="repeat1" value="#{repeatValues}" var="row" offset="1" size="3" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
+ <ui:repeat id="repeat1_7" value="#{repeatValues}" var="row" offset="1" size="6" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
+ <ui:repeat id="repeat1_8" value="#{repeatValues}" var="row" offset="1" size="7" >
+ <h:outputText id="outputText" value="#{row}" />
+ </ui:repeat>
</h:form>
</body>
</html>