[richfaces-svn-commits] JBoss Rich Faces SVN: r4691 - in trunk/sandbox/ui/columns/src/main: java/org/richfaces/tag and 1 other directories.
richfaces-svn-commits at lists.jboss.org
richfaces-svn-commits at lists.jboss.org
Tue Dec 11 05:39:41 EST 2007
Author: andrei_exadel
Date: 2007-12-11 05:39:41 -0500 (Tue, 11 Dec 2007)
New Revision: 4691
Modified:
trunk/sandbox/ui/columns/src/main/config/component/columns.xml
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 begin 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 09:00:51 UTC (rev 4690)
+++ trunk/sandbox/ui/columns/src/main/config/component/columns.xml 2007-12-11 10:39:41 UTC (rev 4691)
@@ -48,12 +48,19 @@
</description>
</property>
<property>
- <name>end</name>
+ <name>columns</name>
<classname>java.lang.Object</classname>
<description>
Count of columns
</description>
</property>
+ <property>
+ <name>begin</name>
+ <classname>java.lang.Object</classname>
+ <description>
+ The first iteration item
+ </description>
+ </property>
<property disabled="true">
<name>header</name>
</property>
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 09:00:51 UTC (rev 4690)
+++ trunk/sandbox/ui/columns/src/main/java/org/richfaces/tag/AbstractColumnsTag.java 2007-12-11 10:39:41 UTC (rev 4691)
@@ -32,7 +32,6 @@
import org.richfaces.iterator.ForEachIterator;
import org.richfaces.iterator.SimpleForEachIterator;
-
/**
* Class provides implementation for columns tag
*
@@ -41,7 +40,7 @@
*/
public abstract class AbstractColumnsTag extends UIComponentClassicTagBase
implements IterationTag {
-
+
/** Column component type */
private static final String _componentType = "org.richfaces.Column";
@@ -70,9 +69,12 @@
/** Value attribute value */
protected Object rawItems; // our 'raw' items
- /** End attribute - defines count of column if value attr hasn't been defined*/
- private ValueExpression end;
+ /** End attribute - defines count of column if value attr hasn't been defined */
+ private ValueExpression columns;
+ /** Begin attribute - defines the first iteration item */
+ private ValueExpression begin;
+
/** Index attr - defines page variable for current column counter */
private ValueExpression _index;
@@ -80,8 +82,11 @@
private String indexId;
/** Integer value of end attr. */
- private Integer _end;
+ private Integer _columns;
+ /** Integer value of begin attr. */
+ private Integer _begin;
+
/** String value of var attr */
private String itemId = null;
@@ -492,7 +497,7 @@
@Override
public int doAfterBody() throws JspException {
- if (hasNext()) {
+ if (hasNext()) {
loop();
} else
return EVAL_BODY_INCLUDE;
@@ -502,13 +507,16 @@
return EVAL_BODY_AGAIN;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.webapp.UIComponentClassicTagBase#addFacet(java.lang.String)
*/
protected void addFacet(String name) {
super.addFacet(name);
-
- // add created component in facet in childrenList to reduce duplicated Id exp.
+
+ // add created component in facet in childrenList to reduce duplicated
+ // Id exp.
if (this.component != null && this.component.getFacets() != null) {
Map<String, UIComponent> facets = this.component.getFacets();
Iterator<UIComponent> it = facets.values().iterator();
@@ -567,7 +575,8 @@
}
/**
- * Method is invoking by each iteration of body again rendering
+ * Method is invoking by each iteration of body again rendering
+ *
* @throws JspTagException
*/
private void loop() throws JspTagException {
@@ -583,6 +592,7 @@
/**
* Creates column instance
+ *
* @return
*/
private UIComponent createColumn() {
@@ -591,35 +601,36 @@
component.setId(getFacesContext().getViewRoot().createUniqueId());
initColumnByThis(component);
-
+
this.component = component;
this.parentTag = getParentUIComponentClassicTagBase(pageContext);
this.previous = component;
return component;
}
-
+
/**
- * Inits column component by columns tag attrs
+ * Inits column component by columns tag attrs
+ *
* @param column
*/
- void initColumnByThis (UIComponent column) {
- column.setValueExpression("style",_style);
- column.setValueExpression("styleClass",_styleClass);
- column.setValueExpression("colspan",_colspan);
- column.setValueExpression("rowspan",_rowspan);
- column.setValueExpression("breakBefore",_breakBefore);
- column.setValueExpression("headerClass",_headerClass);
- column.setValueExpression("footerClass",_footerClass);
- column.setValueExpression("width",_width);
- column.setValueExpression("sortable",_sortable);
- column.setValueExpression("sortExpression",_sortExpression);
- column.setValueExpression("rendered",rendered);
+ void initColumnByThis(UIComponent column) {
+ column.setValueExpression("style", _style);
+ column.setValueExpression("styleClass", _styleClass);
+ column.setValueExpression("colspan", _colspan);
+ column.setValueExpression("rowspan", _rowspan);
+ column.setValueExpression("breakBefore", _breakBefore);
+ column.setValueExpression("headerClass", _headerClass);
+ column.setValueExpression("footerClass", _footerClass);
+ column.setValueExpression("width", _width);
+ column.setValueExpression("sortable", _sortable);
+ column.setValueExpression("sortExpression", _sortExpression);
+ column.setValueExpression("rendered", rendered);
}
-
/**
* Returns true if this is the first loop of columns tag
+ *
* @return
*/
private boolean atFirst() {
@@ -633,9 +644,9 @@
*/
@Override
public int doStartTag() throws JspException {
-
+
prepare();
-
+
if (created) {
dataTable.getChildren().clear();
created = false;
@@ -654,7 +665,8 @@
}
/**
- * Method prepares all we need for starting of tag rendering
+ * Method prepares all we need for starting of tag rendering
+ *
* @throws JspTagException
*/
private void prepare() throws JspTagException {
@@ -676,9 +688,11 @@
.supportedTypeForEachIterator(rawItems);
} else {
// no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(_end - 1);
+ items = SimpleForEachIterator.beginEndForEachIterator(_columns - 1);
}
+ correctFirst();
+
/*
* ResultSet no more supported in <c:forEach> // step must be 1 when
* ResultSet is passed in if (rawItems instanceof ResultSet && step !=
@@ -689,22 +703,22 @@
}
/**
- * Extracts integer value from end attr
+ * Extracts integer value from end attr
*/
- private void initEnd() {
- if (end != null) {
- if (end instanceof ValueExpression)
+ private void initColumnsCount() {
+ if (columns != null) {
+ if (columns instanceof ValueExpression)
try {
- String t = (String) end.getValue(getELContext());
- _end = Integer.parseInt(t);
- if (_end < 0) {
- _end = 0; // If end is negative set up zero
+ String t = (String) columns.getValue(getELContext());
+ _columns = Integer.parseInt(t);
+ if (_columns < 0) {
+ _columns = 0; // If end is negative set up zero
}
} catch (Exception e) {
- _end = 0;
+ _columns = 0;
}
} else {
- _end = 0;
+ _columns = 0;
}
}
@@ -721,6 +735,7 @@
}
}
+
/**
* Extracts string value from index attr
*/
@@ -736,16 +751,38 @@
}
/**
+ * Extracts string value from index attr
+ */
+ private void initBegin() {
+ _begin = 0;
+ if (begin != null) {
+ try {
+ String t = (String) begin.getValue(getELContext());
+ _begin = Integer.parseInt(t);
+ _begin--; // correct begin value
+ if (_begin < 0) {
+ _begin = 0;
+ }
+ } catch (ClassCastException e) {
+ _begin = 0;
+ }
+
+ }
+ }
+
+ /**
* Extracts tags attributes values
*/
private void initVariables() {
- initEnd();
+ initColumnsCount();
initIndex();
initVar();
+ initBegin();
}
/**
- * Return true if we didn't complete column's count
+ * Return true if we didn't complete column's count
+ *
* @return
* @throws JspTagException
*/
@@ -754,7 +791,8 @@
}
/**
- * Iterate to next column
+ * Iterate to next column
+ *
* @return
* @throws JspTagException
*/
@@ -775,14 +813,18 @@
return super.getBodyContent();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.webapp.UIComponentClassicTagBase#setProperties(javax.faces.component.UIComponent)
*/
protected void setProperties(UIComponent component) {
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see javax.faces.webapp.UIComponentClassicTagBase#hasBinding()
*/
protected boolean hasBinding() {
@@ -803,7 +845,8 @@
}
/**
- * Sets page request variables
+ * Sets page request variables
+ *
* @throws JspTagException
*/
private void exposeVariables() throws JspTagException {
@@ -824,7 +867,6 @@
*/
// Set up var variable
-
if (itemId != null) {
if (index == null)
pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
@@ -840,26 +882,27 @@
}
// Set up index variable
-
+
if (indexId != null) {
if (index == null)
pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
else {
IteratedIndexExpression indexExpression = new IteratedIndexExpression(
- index);
+ index - _begin);
VariableMapper vm = pageContext.getELContext()
.getVariableMapper();
if (vm != null) {
vm.setVariable(indexId, indexExpression);
}
- pageContext.setAttribute(indexId, index);
+ pageContext.setAttribute(indexId, index - _begin);
}
}
}
/**
- * Return expression for page variables
+ * Return expression for page variables
+ *
* @param expr
* @return
*/
@@ -891,6 +934,23 @@
}
/**
+ * Inits first iteration item
+ */
+ private void correctFirst() {
+ try {
+ if (items != null) {
+ if (_begin > 0 && (index < (_begin-1))) {
+ while ((index < (_begin -1)) && hasNext()) {
+ next();
+ }
+ }
+ }
+ } catch (Exception e) {
+ // TODO: handle exception
+ }
+ }
+
+ /**
* <p>
* Pop the top {@link UIComponentTag} instance off of our component tag
* stack, deleting the stack if this was the last entry.
@@ -934,21 +994,36 @@
}
/**
- * @return the end
+ * @return the begin
*/
- public ValueExpression getEnd() {
- return end;
+ public ValueExpression getBegin() {
+ return begin;
}
/**
- * @param end
- * the end to set
+ * @param begin
+ * the begin to set
*/
- public void setEnd(ValueExpression end) {
- this.end = end;
+ public void setBegin(ValueExpression begin) {
+ this.begin = begin;
}
/**
+ * @return the columns
+ */
+ public ValueExpression getColumns() {
+ return columns;
+ }
+
+ /**
+ * @param columns
+ * the columns to set
+ */
+ public void setColumns(ValueExpression columns) {
+ this.columns = columns;
+ }
+
+ /**
* @return the index
*/
public ValueExpression getIndex() {
@@ -1220,7 +1295,7 @@
/**
* @author Andrey Markavtsov
* @version $Id: IteratedIndexExpression.java,v 1.2 2007/12/06 01:20:43
- *
+ *
*/
final class IteratedIndexExpression extends ValueExpression {
@@ -1286,8 +1361,8 @@
*
*/
public IndexedValueExpression(ValueExpression orig, int i) {
- this.i = new Integer(i);
- this.orig = orig;
+ this.i = new Integer(i);
+ this.orig = orig;
}
/*
@@ -1296,12 +1371,12 @@
* @see javax.el.ValueExpression#getValue(javax.el.ELContext)
*/
public Object getValue(ELContext context) {
- Object base = this.orig.getValue(context);
- if (base != null) {
- context.setPropertyResolved(false);
- return context.getELResolver().getValue(context, base, i);
- }
- return null;
+ Object base = this.orig.getValue(context);
+ if (base != null) {
+ context.setPropertyResolved(false);
+ return context.getELResolver().getValue(context, base, i);
+ }
+ return null;
}
/*
@@ -1311,11 +1386,11 @@
* java.lang.Object)
*/
public void setValue(ELContext context, Object value) {
- Object base = this.orig.getValue(context);
- if (base != null) {
- context.setPropertyResolved(false);
- context.getELResolver().setValue(context, base, i, value);
- }
+ Object base = this.orig.getValue(context);
+ if (base != null) {
+ context.setPropertyResolved(false);
+ context.getELResolver().setValue(context, base, i, value);
+ }
}
/*
@@ -1324,12 +1399,12 @@
* @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
*/
public boolean isReadOnly(ELContext context) {
- Object base = this.orig.getValue(context);
- if (base != null) {
- context.setPropertyResolved(false);
- return context.getELResolver().isReadOnly(context, base, i);
- }
- return true;
+ Object base = this.orig.getValue(context);
+ if (base != null) {
+ context.setPropertyResolved(false);
+ return context.getELResolver().isReadOnly(context, base, i);
+ }
+ return true;
}
/*
@@ -1338,12 +1413,12 @@
* @see javax.el.ValueExpression#getType(javax.el.ELContext)
*/
public Class getType(ELContext context) {
- Object base = this.orig.getValue(context);
- if (base != null) {
- context.setPropertyResolved(false);
- return context.getELResolver().getType(context, base, i);
- }
- return null;
+ Object base = this.orig.getValue(context);
+ if (base != null) {
+ context.setPropertyResolved(false);
+ return context.getELResolver().getType(context, base, i);
+ }
+ return null;
}
/*
@@ -1352,7 +1427,7 @@
* @see javax.el.ValueExpression#getExpectedType()
*/
public Class getExpectedType() {
- return Object.class;
+ return Object.class;
}
/*
@@ -1361,7 +1436,7 @@
* @see javax.el.Expression#getExpressionString()
*/
public String getExpressionString() {
- return this.orig.getExpressionString();
+ return this.orig.getExpressionString();
}
/*
@@ -1370,7 +1445,7 @@
* @see javax.el.Expression#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
- return this.orig.equals(obj);
+ return this.orig.equals(obj);
}
/*
@@ -1379,7 +1454,7 @@
* @see javax.el.Expression#hashCode()
*/
public int hashCode() {
- return this.orig.hashCode();
+ return this.orig.hashCode();
}
/*
@@ -1388,7 +1463,7 @@
* @see javax.el.Expression#isLiteralText()
*/
public boolean isLiteralText() {
- return false;
+ return false;
}
}
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 09:00:51 UTC (rev 4690)
+++ trunk/sandbox/ui/columns/src/main/java/org/richfaces/taglib/html/facelets/ColumnsHandler.java 2007-12-11 10:39:41 UTC (rev 4691)
@@ -7,6 +7,7 @@
package org.richfaces.taglib.html.facelets;
import java.io.IOException;
+import java.io.Serializable;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
@@ -42,7 +43,10 @@
private TagAttribute value;
/** end attribute */
- private TagAttribute end;
+ private TagAttribute columns;
+
+ /** begin attribute */
+ private TagAttribute begin;
/** var attribute */
private TagAttribute var;
@@ -50,9 +54,6 @@
/** index attribute */
private TagAttribute index;
- /** rendered attribute */
- private TagAttribute rendered;
-
/** Iterator for columns's tag value attribute */
protected ForEachIterator items; // our 'digested' items
@@ -61,9 +62,12 @@
/** Var attr - defines page variable for current item */
private String _indexId;
+
+ /** Integer value begin attr*/
+ private Integer _begin;
/** Integer value of end attr. */
- private Integer _end;
+ private Integer _columns;
/** String value of var attr */
private String _itemId = null;
@@ -94,9 +98,10 @@
* Extracts tags attributes values
*/
private void initVariables(FaceletContext ctx) {
- initEnd(ctx);
+ initColumnsCount(ctx);
initIndex(ctx);
initVar(ctx);
+ initBegin(ctx);
}
/**
@@ -124,18 +129,34 @@
.supportedTypeForEachIterator(rawItems);
} else {
// no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(_end - 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()) {
+ next(ctx);
+ }
+ }
+ }
+ }
/**
* Return true if we didn't complete column's count
@@ -171,21 +192,42 @@
/**
* Extracts integer value from end attr
*/
- private void initEnd(FaceletContext ctx) {
- this.end = getAttribute("end");
- if (end != null) {
+ private void initColumnsCount(FaceletContext ctx) {
+ this.columns = getAttribute("columns");
+ if (columns != null) {
try {
- _end = Integer.parseInt((String)end.getObject(ctx));
- if (_end < 0) {
- _end = 0; // If end is negative set up zero
+ _columns = Integer.parseInt((String)columns.getObject(ctx));
+ if (_columns < 0) {
+ _columns = 0; // If end is negative set up zero
}
} catch (Exception e) {
- _end = 0;
+ _columns = 0;
}
} else {
- _end = 0;
+ _columns = 0;
}
}
+
+
+ /**
+ * Extracts integer value from end attr
+ */
+ private void initBegin(FaceletContext ctx) {
+ this.begin = getAttribute("begin");
+ if (begin != null) {
+ try {
+ _begin = Integer.parseInt((String)begin.getObject(ctx));
+ _begin--; // - 1
+ if (_begin < 0) {
+ _begin = 0; // If end is negative set up zero
+ }
+ } catch (Exception e) {
+ _begin = 0;
+ }
+ } else {
+ _begin = 0;
+ }
+ }
/**
* Extracts string value from var attr
@@ -273,7 +315,7 @@
if (value != null) {
ValueExpression srcVE = value.getValueExpression(ctx,
Object.class);
- ValueExpression ve = getVarExpression(ctx, srcVE, k);
+ ValueExpression ve = getVarExpression(ctx, srcVE, k + _begin);
vm.setVariable(_itemId, ve);
}
}
@@ -352,7 +394,7 @@
c.setRendered(false);
}
- if (vCounter == _index || atFirst()) {
+ if ((vCounter == (_index - _begin)) || atFirst()) {
release();
return;
}
@@ -388,7 +430,7 @@
* @author Kin-man Chung
* @version $Id: IteratedExpression.java,v 1.3 2005/12/08 01:20:43 kchung Exp $
*/
-final class IteratedExpression {
+final class IteratedExpression implements Serializable{
private static final long serialVersionUID = 1L;
protected final ValueExpression orig;
@@ -479,7 +521,8 @@
* @version $Id: IteratedValueExpression.java,v 1.2 2005/12/08 01:20:43 kchung
* Exp $
*/
-final class IteratedValueExpression extends ValueExpression {
+final class IteratedValueExpression extends ValueExpression
+implements Serializable{
private static final long serialVersionUID = 1L;
protected final int i;
@@ -531,7 +574,8 @@
* @version $Id: IteratedIndexExpression.java,v 1.2 2007/12/06 01:20:43
*
*/
-final class IteratedIndexExpression extends ValueExpression {
+final class IteratedIndexExpression extends ValueExpression
+implements Serializable{
private static final long serialVersionUID = 1L;
protected final Integer i;
@@ -580,7 +624,8 @@
* @author Jacob Hookom
* @version $Id: IndexedValueExpression.java,v 1.3 2005/08/24 04:38:52 jhook Exp $
*/
-final class IndexedValueExpression extends ValueExpression {
+final class IndexedValueExpression extends ValueExpression
+implements Serializable{
/**
*
More information about the richfaces-svn-commits
mailing list