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/27 07:57:31 UTC

svn commit: r1827811 - 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/ shared-p...

Author: tandraschko
Date: Tue Mar 27 07:57:31 2018
New Revision: 1827811

URL: http://svn.apache.org/viewvc?rev=1827811&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/testUIRepeatEmpty.xhtml
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/shared-public/src/   (props changed)

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=1827811&r1=1827810&r2=1827811&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 Tue Mar 27 07:57:31 2018
@@ -96,6 +96,8 @@ public class UIRepeat extends UIComponen
     
     // will be set to false if the data should not be refreshed at the beginning of the encode phase
     private boolean _isValidChilds = true;
+    
+    private boolean _emptyModel = false;
 
     private int _end = -1;
     
@@ -354,7 +356,7 @@ public class UIRepeat extends UIComponen
 
     private boolean _isIndexAvailable()
     {
-        return getDataModel() == EMPTY_MODEL || getDataModel().isRowAvailable();
+        return _emptyModel || getDataModel().isRowAvailable();
     }
 
     private void _restoreScopeValues()
@@ -730,7 +732,7 @@ public class UIRepeat extends UIComponen
      */
     public int getRowCount()
     {
-        if (getValue() == null) // empty model
+        if (_emptyModel) // empty model
         {
             return (getEnd() - getBegin())/(getStep() <= 0 ? 1 : getStep());
         }
@@ -807,10 +809,9 @@ public class UIRepeat extends UIComponen
         if (_index != -1)
         {
             String var = getVar();
-            boolean emptyModel = getDataModel() == EMPTY_MODEL;
-            if (var != null && (emptyModel || localModel.isRowAvailable()))
+            if (var != null && (_emptyModel || localModel.isRowAvailable()))
             {
-                if (emptyModel)
+                if (_emptyModel)
                 {
                     getFacesContext().getExternalContext().getRequestMap().put(var, _index);
                 }
@@ -885,10 +886,10 @@ public class UIRepeat extends UIComponen
     private void _validateAttributes() throws FacesException
     {
         
-        boolean emptyModel = getDataModel() == EMPTY_MODEL;
         int begin = getBegin();
         int end = getEnd();
         int size = getSize();
+        _emptyModel = getDataModel() == EMPTY_MODEL && begin != -1 && end != -1;
         int count = getRowCount();
         int offset = getOffset();
         if (begin == -1)
@@ -901,12 +902,7 @@ public class UIRepeat extends UIComponen
        
         if (end == -1 && size == -1) 
         {
-            if (emptyModel && end == -1)
-            {
-                throw new FacesException("on empty models, you must define begin and " +
-                        "end");
-            }
-            else if (begin == -1) 
+            if (begin == -1) 
             {
                 end = getDataModel().getRowCount();
             } 
@@ -917,8 +913,8 @@ public class UIRepeat extends UIComponen
         }
         
         int step = getStep();
-        boolean sizeIsEnd = emptyModel;
-        boolean countdown = emptyModel && end < begin;
+        boolean sizeIsEnd = _emptyModel;
+        boolean countdown = _emptyModel && end < begin;
 
         if (size == -1)
         {
@@ -935,7 +931,7 @@ public class UIRepeat extends UIComponen
         
         step = countdown && step > 0 ? -step : step;
 
-        if (emptyModel)
+        if (_emptyModel)
         {
             if (step > 0 && (end < begin))
             {
@@ -981,23 +977,23 @@ public class UIRepeat extends UIComponen
                         "than collection size");
             }
         }
-        if (!emptyModel && (begin >= 0) && (begin > end))
+        if (!_emptyModel && (begin >= 0) && (begin > end))
         {
             throw new FacesException("begin cannot be greater " +
                     "end");
         }
-        if (!emptyModel && (size > -1) && (offset > end))
+        if (!_emptyModel && (size > -1) && (offset > end))
         {
             throw new FacesException("iteration offset cannot be greater " +
                     "than collection size");
         }
 
-        if (!emptyModel && step == -1)
+        if (!_emptyModel && step == -1)
         {
             setStep(1);
         }
 
-        if (!emptyModel && step < 0)
+        if (!_emptyModel && step < 0)
         {
             throw new FacesException("iteration step size cannot be less " +
                     "than zero");

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=1827811&r1=1827810&r2=1827811&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 Tue Mar 27 07:57:31 2018
@@ -20,6 +20,8 @@ package org.apache.myfaces.view.facelets
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import javax.el.ELContext;
@@ -828,4 +830,56 @@ public class RepeatTestCase extends Face
         Assert.assertFalse(content.contains("Hello 0"));
         Assert.assertFalse(content.contains("Hello 4"));
     }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInvokeOnNullModel() throws IOException
+    {                
+        final List<String> modelValues = null;
+        final List<String> loadedModelValues = Arrays.asList("Claire", "Michael");
+        facesContext.getExternalContext().getRequestMap().put("modelValues", modelValues);
+        facesContext.getExternalContext().getRequestMap().put("loadedModelValues", loadedModelValues);
+        UIViewRoot root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root, "testUIRepeatEmpty.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.assertFalse(content.contains("Hello "));
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testInvokeOnEmptyList() throws IOException
+    {                
+        final List<String> modelValues = Collections.emptyList();
+        final List<String> loadedModelValues = Arrays.asList("Claire", "Michael");
+        facesContext.getExternalContext().getRequestMap().put("modelValues", modelValues);
+        facesContext.getExternalContext().getRequestMap().put("loadedModelValues", loadedModelValues);
+        UIViewRoot root = facesContext.getViewRoot();
+        vdl.buildView(facesContext, root, "testUIRepeatEmpty.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.assertFalse(content.contains("Hello "));
+    }
 }

Added: myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatEmpty.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatEmpty.xhtml?rev=1827811&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatEmpty.xhtml (added)
+++ myfaces/core/branches/2.3.x/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/ui/testUIRepeatEmpty.xhtml Tue Mar 27 07:57:31 2018
@@ -0,0 +1,31 @@
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core"
+	xmlns:ui="http://java.sun.com/jsf/facelets">
+<head>
+</head>
+<body>
+    <h:form id="form">
+        <ui:repeat id="repeat" var="i" value="#{modelValues}">
+            <h:outputText id="outputText" value="Hello #{i}" />
+        </ui:repeat>
+        <ui:repeat id="good" var="i" value="#{loadedModelValues}">
+            <h:outputText id="outputText" value="Hallo #{i}" />
+        </ui:repeat>
+    </h:form>
+</body>
+</html>

Propchange: myfaces/core/branches/2.3.x/shared-public/src/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 27 07:57:31 2018
@@ -1,5 +1,5 @@
 /myfaces/core/branches/2.1.x/shared-public/src: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/shared-public/src:1396979-1406260,1410177-1410189,1410207-1420939,1420950-1421674,1433517
-/myfaces/core/trunk/shared-public/src: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/shared-public/src: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/shared/trunk/core/src:1085636-1098584
 /myfaces/shared/trunk_3.0.x/core/src:805066-833809,881094-924402,940133-941950