myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From embre...@apache.org
Subject svn commit: r1805225 - in /myfaces/core/branches/2.3.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/
Date Wed, 16 Aug 2017 16:53:12 GMT
Author: embreijo
Date: Wed Aug 16 16:53:12 2017
New Revision: 1805225

URL: http://svn.apache.org/viewvc?rev=1805225&view=rev
Log:
MYFACES-4131 <ui:repeat/> begin and end do not look to be implemented / working

Modified:
    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
    myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml

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=1805225&r1=1805224&r2=1805225&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 Aug 16 16:53:12 2017
@@ -154,6 +154,28 @@ public class UIRepeat extends UIComponen
         getStateHelper().put(PropertyKeys.step, step );
     }
     
+    @JSFProperty
+    public int getBegin()
+    {
+        return (Integer) getStateHelper().eval(PropertyKeys.begin, -1);
+    }
+
+    public void setBegin(int begin)
+    {
+        getStateHelper().put(PropertyKeys.begin, begin );
+    }
+    
+    @JSFProperty
+    public int getEnd()
+    {
+        return (Integer) getStateHelper().eval(PropertyKeys.end, -1);
+    }
+
+    public void setEnd(int end)
+    {
+        getStateHelper().put(PropertyKeys.end, end );
+    }
+    
     @JSFProperty(literalOnly=true)
     public String getVar()
     {
@@ -303,8 +325,15 @@ public class UIRepeat extends UIComponen
     
     private RepeatStatus _getRepeatStatus()
     {
+        int begin = getBegin();
+        if (begin == -1) 
+        {
+            begin = getOffset();
+        }
+        
         return new RepeatStatus(_count == 0, _index + getStep() >= getDataModel().getRowCount(),
-            _count, _index, getOffset(), _end, getStep());
+            _count, _index, begin, _end, getStep());
+        
     }
 
     private void _captureScopeValues()
@@ -851,16 +880,46 @@ public class UIRepeat extends UIComponen
 
     private void _validateAttributes() throws FacesException
     {
-        int begin = getOffset();
-        int end = getDataModel().getRowCount();
+        
+        int begin = getBegin();
+        int end = getEnd();
         int size = getSize();
+        int count = getDataModel().getRowCount();
+        int offset = getOffset();
+        if (begin == -1)
+        {
+            if (size >= 0)
+            {
+                end = getOffset() + getSize();
+            }
+        }      
+       
+        if (end == -1 && size == -1) 
+        {
+            if (begin == -1) 
+            {
+                end = getDataModel().getRowCount();
+            } 
+            else 
+            {
+                end = getDataModel().getRowCount() - 1;
+            }
+        }
+        
         int step = getStep();
         boolean sizeIsEnd = false;
 
         if (size == -1)
         {
-            size = end;
-            sizeIsEnd = true;
+            if (begin == -1)
+            {
+                size =  end;
+                sizeIsEnd = true;
+            } 
+            else 
+            {
+                size = end - begin + 1;
+            }     
         }
 
         if (end >= 0)
@@ -870,15 +929,38 @@ public class UIRepeat extends UIComponen
                 throw new FacesException("iteration size cannot be less " +
                         "than zero");
             }
-
-            else if (!sizeIsEnd && (begin + size) > end)
+            else if (!sizeIsEnd && (begin == -1) && (offset + size) >
end)
+            {
+                throw new FacesException("iteration size cannot be greater " +
+                        "than collection size");
+            }
+            else if (!sizeIsEnd && (begin == -1) && (offset + size) >
count)
             {
                 throw new FacesException("iteration size cannot be greater " +
                         "than collection size");
             }
+            else if (!sizeIsEnd && (begin >= 0) && (begin + size) >
end+1)
+            {
+                throw new FacesException("iteration size cannot be greater " +
+                        "than collection size");
+            }
+            else if(!sizeIsEnd && (begin >= 0) && (end+1 > count))
+            {
+                throw new FacesException("end cannot be greater " +
+                        "than collection size");
+            }
+            else if(!sizeIsEnd && (begin >= 0) && (begin > count))
+            {
+                throw new FacesException("begin cannot be greater " +
+                        "than collection size");
+            }
         }
-
-        if ((size > -1) && (begin > end))
+        if ((begin >= 0) && (begin > end))
+        {
+            throw new FacesException("begin cannot be greater " +
+                    "end");
+        }
+        if ((size > -1) && (offset > end))
         {
             throw new FacesException("iteration offset cannot be greater " +
                     "than collection size");
@@ -901,8 +983,9 @@ public class UIRepeat extends UIComponen
                     "to zero");
         }
 
-        _end = size;
-        //_step = step;
+        
+        _end = end;
+        
     }
 
     public void process(FacesContext faces, PhaseId phase)
@@ -925,11 +1008,21 @@ public class UIRepeat extends UIComponen
             // has children
             if (getChildCount() > 0)
             {
-                int i = getOffset();
-                int end = getSize();
-                int step = getStep();
-                end = (end >= 0) ? i + end : Integer.MAX_VALUE - 1;
+                int i = getOffset();               
                 
+                int begin = getBegin();
+                int end = getEnd(); 
+                if (begin == -1)
+                {
+                    end = getSize();
+                    end = (end >= 0) ? i + end - 1 : Integer.MAX_VALUE - 1;
+                }
+                
+                if (begin >= 0) 
+                {
+                    i = begin;
+                }
+                int step = getStep();
                 // grab renderer
                 String rendererType = getRendererType();
                 Renderer renderer = null;
@@ -941,7 +1034,8 @@ 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)
@@ -1719,5 +1813,7 @@ public class UIRepeat extends UIComponen
         , varStatus
         , offset
         , step
+        , begin
+        , end
     }
 }

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=1805225&r1=1805224&r2=1805225&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 Aug 16 16:53:12 2017
@@ -404,7 +404,37 @@ public class RepeatTestCase extends Face
         int itemIndex3 = content.indexOf("B3");
         Assert.assertEquals(-1, itemIndex3);
     }
+    
+    @Test
+    public void testRepeatBegin_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:repeatbegin0");
+        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.assertNotSame(-1, itemIndex3);
+    }
 
+    
     @Test
     public void testRepeatOffset_0_7() throws Exception 
     {
@@ -443,6 +473,43 @@ public class RepeatTestCase extends Face
     }
     
     @Test
+    public void testRepeatBegin_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:repeatbegin0_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"};
@@ -471,6 +538,34 @@ public class RepeatTestCase extends Face
     }
     
     @Test
+    public void testRepeatBegin_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:repeatbegin0_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"};
@@ -502,7 +597,40 @@ public class RepeatTestCase extends Face
         int itemIndex5 = content.indexOf("B5", itemIndex4);
         Assert.assertEquals(-1, itemIndex5);
     }
+    
+    @Test
+    public void testRepeatBegin_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:repeatbegin1");
+        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 
     {
@@ -541,6 +669,43 @@ public class RepeatTestCase extends Face
     }
     
     @Test
+    public void testRepeatBegin_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:repeatbegin1_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"};
@@ -553,6 +718,34 @@ public class RepeatTestCase extends Face
         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 testRepeatBegin_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:repeatbegin1_8");
+        Assert.assertNotNull(repeat);
+        
+        FastWriter fw = new FastWriter();
         ResponseWriter rw = facesContext.getResponseWriter();
         rw = rw.cloneWithWriter(fw);
         facesContext.setResponseWriter(rw);

Modified: myfaces/core/branches/2.3.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.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml?rev=1805225&r1=1805224&r2=1805225&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml
(original)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/ui_repeat_offset.xhtml
Wed Aug 16 16:53:12 2017
@@ -41,6 +41,24 @@
         <ui:repeat id="repeat1_8" value="#{repeatValues}" var="row" offset="1" size="7"
>
             <h:outputText id="outputText" value="#{row}" />
         </ui:repeat>        
+        <ui:repeat id="repeatbegin0" value="#{repeatValues}" var="row" begin="0" end="2"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>
+        <ui:repeat id="repeatbegin0_7" value="#{repeatValues}" var="row" begin="0" end="6"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>
+        <ui:repeat id="repeatbegin0_8" value="#{repeatValues}" var="row" begin="0" end="7"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>
+         <ui:repeat id="repeatbegin1" value="#{repeatValues}" var="row" begin="1" end="3"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>
+        <ui:repeat id="repeatbegin1_7" value="#{repeatValues}" var="row" begin="1" end="6"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>
+        <ui:repeat id="repeatbegin1_8" value="#{repeatValues}" var="row" begin="1" end="7"
>
+            <h:outputText id="outputText" value="#{row}" />
+        </ui:repeat>        
     </h:form>
 </body>
 </html>



Mime
View raw message