You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by cj...@apache.org on 2010/03/02 21:07:26 UTC

svn commit: r918168 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component: RepeatRenderer.java RepeatStatus.java UIRepeat.java

Author: cjhoward
Date: Tue Mar  2 20:07:25 2010
New Revision: 918168

URL: http://svn.apache.org/viewvc?rev=918168&view=rev
Log:
MYFACES-2508 - UIRepeat did not support the "varStatus" attribute.

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java   (with props)
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatRenderer.java
    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/RepeatRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatRenderer.java?rev=918168&r1=918167&r2=918168&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatRenderer.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatRenderer.java Tue Mar  2 20:07:25 2010
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.util.Map;
 
+import javax.el.ELContext;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
@@ -52,6 +53,8 @@
         {
             Map<String, Object> a = component.getAttributes();
             String tag = (String) a.get("alias.element");
+            ELContext elContext = context.getELContext();
+            UIRepeat repeat = (UIRepeat) component;
             if (tag != null)
             {
                 ResponseWriter out = context.getResponseWriter();
@@ -72,6 +75,12 @@
                 }
             }
             
+            if (repeat.getVarStatus() != null)
+            {
+                elContext.getELResolver().setValue (elContext, null,
+                    repeat.getVarStatus(), repeat.getStatus());
+            }
+            
             for (UIComponent child : component.getChildren())
             {
                 child.encodeAll(context);
@@ -87,7 +96,14 @@
     @Override
     public void encodeEnd(FacesContext context, UIComponent component) throws IOException
     {
-
+        ELContext elContext = context.getELContext();
+        UIRepeat repeat = (UIRepeat) component;
+        
+        if (repeat.getVarStatus() != null)
+        {
+            elContext.getELResolver().setValue (elContext, null,
+                repeat.getVarStatus(), null);
+        }
     }
 
     @Override

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java?rev=918168&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java Tue Mar  2 20:07:25 2010
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.myfaces.view.facelets.component;
+
+import java.io.Serializable;
+
+/**
+ * @version $Id$
+ */
+public final class RepeatStatus implements Serializable
+{
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+    
+    private final int count;
+    
+    private final int index;
+
+    private final boolean first;
+
+    private final boolean last;
+
+    private final Integer begin;
+
+    private final Integer end;
+
+    private final Integer step;
+    
+    public RepeatStatus(boolean first, boolean last, int count, int index, Integer begin, Integer end, Integer step)
+    {
+        this.count = count;
+        this.index = index;
+        this.begin = begin;
+        this.end = end;
+        this.step = step;
+        this.first = first;
+        this.last = last;
+    }
+
+    public boolean isFirst()
+    {
+        return first;
+    }
+
+    public boolean isLast()
+    {
+        return last;
+    }
+    
+    public boolean isEven ()
+    {
+        return ((count % 2) == 0);
+    }
+    
+    public boolean isOdd () {
+        return !isEven();
+    }
+    
+    public Integer getBegin()
+    {
+        if (begin == -1)
+        {
+            return null;
+        }
+        
+        return begin;
+    }
+    
+    public Integer getEnd()
+    {
+        if (end == -1)
+        {
+            return null;
+        }
+        
+        return end;
+    }
+
+    public int getIndex()
+    {
+        return index;
+    }
+
+    public Integer getStep()
+    {
+        if (step == -1)
+        {
+            return null;
+        }
+        
+        return step;
+    }
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/component/RepeatStatus.java
------------------------------------------------------------------------------
    svn:eol-style = LF

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=918168&r1=918167&r2=918168&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 Mar  2 20:07:25 2010
@@ -71,9 +71,11 @@
 
     // variables
     private String _var;
-
-    //FIXME: varStatus isn't used, should support be added? private String _varStatus;
-
+    
+    private int _end = -1;
+    
+    private int _count;
+    
     private int _index = -1;
 
     // scoping
@@ -121,6 +123,12 @@
         _offset = offset;
     }
     
+    protected RepeatStatus getStatus ()
+    {
+        return new RepeatStatus (_count == 0, _index + getStep() >= getDataModel().getRowCount(),
+            _count, _index, getOffset(), _end, getStep());
+    }
+    
     @JSFProperty
     public int getSize()
     {
@@ -441,13 +449,62 @@
         // restore child state
         _restoreChildState();
     }
-
+    
+    private void _validateAttributes () throws FacesException {
+        int begin = getOffset();
+        int end = getDataModel().getRowCount();
+        int size = getSize();
+        int step = getStep();
+        
+        if (size == -1) {
+            size = end;
+        }
+        
+        if (end >= 0) {
+            if (size < 0) {
+                throw new FacesException ("iteration size cannot be less " +
+                    "than zero");
+            }
+            
+            else if (size > end) {
+                throw new FacesException ("iteration size cannot be greater " +
+                    "than collection size");
+            }
+        }
+        
+        if ((size > -1) && (begin > size)) {
+            throw new FacesException ("iteration offset cannot be greater " +
+                "than collection size");
+        }
+        
+        if (step == -1) {
+            step = 1;
+        }
+        
+        if (step < 0) {
+            throw new FacesException ("iteration step size cannot be less " +
+                "than zero");
+        }
+        
+        else if (step == 0) {
+            throw new FacesException ("iteration step size cannot be equal " +
+                "to zero");
+        }
+        
+        _end = size;
+        _step = step;
+    }
+    
     public void process(FacesContext faces, PhaseId phase)
     {
         // stop if not rendered
         if (!isRendered())
             return;
-
+        
+        // validate attributes
+        
+        _validateAttributes();
+        
         // clear datamodel
         _resetDataModel();
 
@@ -462,8 +519,9 @@
             {
                 int i = getOffset();
                 int end = getSize();
+                int step = getStep();
                 end = (end >= 0) ? i + end : Integer.MAX_VALUE - 1;
-
+                
                 // grab renderer
                 String rendererType = getRendererType();
                 Renderer renderer = null;
@@ -471,7 +529,9 @@
                 {
                     renderer = getRenderer(faces);
                 }
-
+                
+                _count = 0;
+                
                 _setIndex(i);
                 while (i <= end && _isIndexAvailable())
                 {
@@ -503,7 +563,9 @@
                         }
                     }
                     
-                    i++;
+                    ++_count;
+                    
+                    i += step;
                     
                     _setIndex(i);
                 }