Author: andrei_exadel
Date: 2007-12-11 07:57:00 -0500 (Tue, 11 Dec 2007)
New Revision: 4695
Modified:
trunk/sandbox/ui/columns/src/main/config/component/columns.xml
trunk/sandbox/ui/columns/src/main/java/org/richfaces/iterator/SimpleForEachIterator.java
trunk/sandbox/ui/columns/src/main/java/org/richfaces/tag/AbstractColumnsTag.java
trunk/sandbox/ui/columns/src/main/java/org/richfaces/taglib/html/facelets/ColumnsHandler.java
Log:
RF-1201 add end attribute
Modified: trunk/sandbox/ui/columns/src/main/config/component/columns.xml
===================================================================
--- trunk/sandbox/ui/columns/src/main/config/component/columns.xml 2007-12-11 12:53:38 UTC
(rev 4694)
+++ trunk/sandbox/ui/columns/src/main/config/component/columns.xml 2007-12-11 12:57:00 UTC
(rev 4695)
@@ -61,6 +61,13 @@
The first iteration item
</description>
</property>
+ <property>
+ <name>end</name>
+ <classname>java.lang.Object</classname>
+ <description>
+ The last iteration item
+ </description>
+ </property>
<property disabled="true">
<name>header</name>
</property>
Modified:
trunk/sandbox/ui/columns/src/main/java/org/richfaces/iterator/SimpleForEachIterator.java
===================================================================
---
trunk/sandbox/ui/columns/src/main/java/org/richfaces/iterator/SimpleForEachIterator.java 2007-12-11
12:53:38 UTC (rev 4694)
+++
trunk/sandbox/ui/columns/src/main/java/org/richfaces/iterator/SimpleForEachIterator.java 2007-12-11
12:57:00 UTC (rev 4695)
@@ -6,6 +6,7 @@
package org.richfaces.iterator;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
@@ -21,7 +22,7 @@
* @author "Andrey Markavtsov"
*
*/
-public class SimpleForEachIterator implements ForEachIterator {
+public class SimpleForEachIterator implements ForEachIterator, Serializable {
private Iterator i;
Modified:
trunk/sandbox/ui/columns/src/main/java/org/richfaces/tag/AbstractColumnsTag.java
===================================================================
---
trunk/sandbox/ui/columns/src/main/java/org/richfaces/tag/AbstractColumnsTag.java 2007-12-11
12:53:38 UTC (rev 4694)
+++
trunk/sandbox/ui/columns/src/main/java/org/richfaces/tag/AbstractColumnsTag.java 2007-12-11
12:57:00 UTC (rev 4695)
@@ -75,6 +75,9 @@
/** Begin attribute - defines the first iteration item */
private ValueExpression begin;
+ /** Begin attribute - defines the last iteration item */
+ private ValueExpression end;
+
/** Index attr - defines page variable for current column counter */
private ValueExpression _index;
@@ -87,6 +90,9 @@
/** Integer value of begin attr. */
private Integer _begin;
+ /** Integer value of end attr. */
+ private Integer _end;
+
/** String value of var attr */
private String itemId = null;
@@ -771,6 +777,25 @@
}
/**
+ * Extracts string value from index attr
+ */
+ private void initEnd() {
+ _end = 0;
+ if (end != null) {
+ try {
+ String t = (String) end.getValue(getELContext());
+ _end = Integer.parseInt(t);
+ if (_end < 0) {
+ _end = 0;
+ }
+ } catch (ClassCastException e) {
+ _end = 0;
+ }
+
+ }
+ }
+
+ /**
* Extracts tags attributes values
*/
private void initVariables() {
@@ -778,6 +803,7 @@
initIndex();
initVar();
initBegin();
+ initEnd();
}
/**
@@ -787,7 +813,11 @@
* @throws JspTagException
*/
private boolean hasNext() throws JspTagException {
- return items.hasNext();
+ if (_end != 0) {
+ return (index < (_end - 1)) ? items.hasNext() : false;
+ } else {
+ return items.hasNext();
+ }
}
/**
@@ -939,8 +969,8 @@
private void correctFirst() {
try {
if (items != null) {
- if (_begin > 0 && (index < (_begin-1))) {
- while ((index < (_begin -1)) && hasNext()) {
+ if (_begin > 0 && (index < (_begin - 1))) {
+ while ((index < (_begin - 1)) && hasNext()) {
next();
}
}
@@ -1038,6 +1068,21 @@
this._index = index;
}
+ /**
+ * @return the end
+ */
+ public ValueExpression getEnd() {
+ return end;
+ }
+
+ /**
+ * @param end
+ * the end to set
+ */
+ public void setEnd(ValueExpression end) {
+ this.end = end;
+ }
+
}
class TypedCollections {
Modified:
trunk/sandbox/ui/columns/src/main/java/org/richfaces/taglib/html/facelets/ColumnsHandler.java
===================================================================
---
trunk/sandbox/ui/columns/src/main/java/org/richfaces/taglib/html/facelets/ColumnsHandler.java 2007-12-11
12:53:38 UTC (rev 4694)
+++
trunk/sandbox/ui/columns/src/main/java/org/richfaces/taglib/html/facelets/ColumnsHandler.java 2007-12-11
12:57:00 UTC (rev 4695)
@@ -22,6 +22,7 @@
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.servlet.jsp.JspTagException;
+import javax.servlet.jsp.PageContext;
import org.richfaces.iterator.ForEachIterator;
import org.richfaces.iterator.SimpleForEachIterator;
@@ -44,7 +45,7 @@
/** end attribute */
private TagAttribute columns;
-
+
/** begin attribute */
private TagAttribute begin;
@@ -54,6 +55,9 @@
/** index attribute */
private TagAttribute index;
+ /** end attribute */
+ private TagAttribute end;
+
/** Iterator for columns's tag value attribute */
protected ForEachIterator items; // our 'digested' items
@@ -62,10 +66,13 @@
/** Var attr - defines page variable for current item */
private String _indexId;
-
- /** Integer value begin attr*/
+
+ /** Integer value begin attr */
private Integer _begin;
+ /** Integer value end attr */
+ private Integer _end;
+
/** Integer value of end attr. */
private Integer _columns;
@@ -102,6 +109,7 @@
initIndex(ctx);
initVar(ctx);
initBegin(ctx);
+ initEnd(ctx);
}
/**
@@ -114,7 +122,7 @@
initVariables(ctx);
try {
-
+
this.value = getAttribute("value");
// produce the right sort of ForEachIterator
@@ -129,29 +137,29 @@
.supportedTypeForEachIterator(rawItems);
} else {
// no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(_columns - 1);
+ items = SimpleForEachIterator
+ .beginEndForEachIterator(_columns - 1);
}
} catch (Exception e) {
// TODO: handle exception
}
-
+
correctFirst(ctx);
-
+
if (hasNext()) {
exposeVariables(ctx, 0);
next(ctx);
}
}
-
-
+
/**
* Inits first iteration item
*/
private void correctFirst(FaceletContext ctx) {
if (items != null) {
if (_begin > 0 && (_index < _begin)) {
- while ( (_index < _begin) && hasNext()) {
+ while ((_index < _begin) && hasNext()) {
next(ctx);
}
}
@@ -166,7 +174,11 @@
*/
private boolean hasNext() {
try {
- return items.hasNext();
+ if (_end != 0) {
+ return (_index < _end) ? items.hasNext() : false;
+ } else {
+ return items.hasNext();
+ }
} catch (Exception e) {
return false;
}
@@ -196,7 +208,7 @@
this.columns = getAttribute("columns");
if (columns != null) {
try {
- _columns = Integer.parseInt((String)columns.getObject(ctx));
+ _columns = Integer.parseInt((String) columns.getObject(ctx));
if (_columns < 0) {
_columns = 0; // If end is negative set up zero
}
@@ -207,17 +219,16 @@
_columns = 0;
}
}
-
-
+
/**
- * Extracts integer value from end attr
+ * Extracts integer value from begin attr
*/
private void initBegin(FaceletContext ctx) {
this.begin = getAttribute("begin");
if (begin != null) {
try {
- _begin = Integer.parseInt((String)begin.getObject(ctx));
- _begin--; // - 1
+ _begin = Integer.parseInt((String) begin.getObject(ctx));
+ _begin--; // - 1
if (_begin < 0) {
_begin = 0; // If end is negative set up zero
}
@@ -230,6 +241,25 @@
}
/**
+ * Extracts integer value from end attr
+ */
+ private void initEnd(FaceletContext ctx) {
+ this.end = getAttribute("end");
+ if (end != null) {
+ try {
+ _end = Integer.parseInt((String) end.getObject(ctx));
+ if (_end < 0) {
+ _end = 0; // If end is negative set up zero
+ }
+ } catch (Exception e) {
+ _end = 0;
+ }
+ } else {
+ _end = 0;
+ }
+ }
+
+ /**
* Extracts string value from var attr
*/
private void initVar(FaceletContext ctx) {
@@ -315,7 +345,8 @@
if (value != null) {
ValueExpression srcVE = value.getValueExpression(ctx,
Object.class);
- ValueExpression ve = getVarExpression(ctx, srcVE, k + _begin);
+ ValueExpression ve = getVarExpression(ctx, srcVE, k
+ + _begin);
vm.setVariable(_itemId, ve);
}
}
@@ -335,6 +366,23 @@
}
/**
+ * Removes page attributes that we have exposed and, if applicable, restores
+ * them to their prior values (and scopes).
+ */
+ private void unExposeVariables(FaceletContext ctx) {
+ VariableMapper vm = ctx.getVariableMapper();
+ // "nested" variables are now simply removed
+ if (_itemId != null) {
+ if (vm != null)
+ vm.setVariable(_itemId, null);
+ }
+ if (_indexId != null) {
+ if (vm != null)
+ vm.setVariable(_indexId, null);
+ }
+ }
+
+ /**
* Return expression for page variables
*
* @param expr
@@ -396,6 +444,7 @@
if ((vCounter == (_index - _begin)) || atFirst()) {
release();
+ unExposeVariables(ctx);
return;
}
@@ -430,7 +479,7 @@
* @author Kin-man Chung
* @version $Id: IteratedExpression.java,v 1.3 2005/12/08 01:20:43 kchung Exp $
*/
-final class IteratedExpression implements Serializable{
+final class IteratedExpression implements Serializable {
private static final long serialVersionUID = 1L;
protected final ValueExpression orig;
@@ -521,8 +570,8 @@
* @version $Id: IteratedValueExpression.java,v 1.2 2005/12/08 01:20:43 kchung
* Exp $
*/
-final class IteratedValueExpression extends ValueExpression
-implements Serializable{
+final class IteratedValueExpression extends ValueExpression implements
+ Serializable {
private static final long serialVersionUID = 1L;
protected final int i;
@@ -574,8 +623,8 @@
* @version $Id: IteratedIndexExpression.java,v 1.2 2007/12/06 01:20:43
*
*/
-final class IteratedIndexExpression extends ValueExpression
-implements Serializable{
+final class IteratedIndexExpression extends ValueExpression implements
+ Serializable {
private static final long serialVersionUID = 1L;
protected final Integer i;
@@ -624,8 +673,8 @@
* @author Jacob Hookom
* @version $Id: IndexedValueExpression.java,v 1.3 2005/08/24 04:38:52 jhook Exp $
*/
-final class IndexedValueExpression extends ValueExpression
-implements Serializable{
+final class IndexedValueExpression extends ValueExpression implements
+ Serializable {
/**
*