Author: andrei_exadel
Date: 2008-03-20 09:49:32 -0400 (Thu, 20 Mar 2008)
New Revision: 6992
Modified:
trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
Log:
RF-2413
Modified: trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java
===================================================================
--- trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-03-20
13:49:29 UTC (rev 6991)
+++ trunk/ui/columns/src/main/java/org/richfaces/taglib/ColumnsTag.java 2008-03-20
13:49:32 UTC (rev 6992)
@@ -6,15 +6,24 @@
package org.richfaces.taglib;
+import java.beans.FeatureDescriptor;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.el.ELContext;
import javax.el.ELException;
+import javax.el.ELResolver;
+import javax.el.ExpressionFactory;
+import javax.el.FunctionMapper;
import javax.el.MethodExpression;
+import javax.el.PropertyNotFoundException;
import javax.el.ValueExpression;
import javax.el.VariableMapper;
import javax.faces.component.UIComponent;
@@ -26,1185 +35,1504 @@
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.IterationTag;
+import org.jaxen.expr.Expr;
import org.richfaces.component.UIColumn;
import org.richfaces.iterator.ForEachIterator;
import org.richfaces.iterator.SimpleForEachIterator;
+import org.richfaces.model.Ordering;
+import com.sun.el.lang.ELSupport;
+import com.sun.el.lang.EvaluationContext;
+import com.sun.faces.el.ELContextImpl;
+
/**
* Class provides implementation for columns tag
*
* @author "Andrey Markavtsov"
*
*/
+/**
+ * @author Andrey
+ *
+ */
public class ColumnsTag extends UIComponentClassicTagBase implements
- IterationTag {
+ IterationTag {
- /** Component type */
- private static final String COLUMN_COMPONENT_TYPE = UIColumn.COMPONENT_TYPE;
+ /** Component type */
+ private static final String COLUMN_COMPONENT_TYPE = UIColumn.COMPONENT_TYPE;
- /** Prefix before id to be assigned for column */
- private static final String COLUMN_ID_PREFIX = "rf";
+ /** Prefix before id to be assigned for column */
+ private static final String COLUMN_ID_PREFIX = "rf";
- /** Current column counter */
- private Integer index = -1;
+ /** Current column counter */
+ private Integer index = -1;
- /** Data table */
- private UIComponent dataTable;
+ /** Data table */
+ private UIComponent dataTable;
- /**
- * <p>
- * The {@link UIComponent} that is being encoded by this tag, if any.
- * </p>
- */
- private UIComponent component = null;
+ private Pattern varPattern = null;
- /** Flag indicates if columns are already created */
- private boolean created = false;
+ private Pattern indexPattern = null;
- /** Iterator for columns's tag value attribute */
- protected ForEachIterator items; // our 'digested' items
+ /**
+ * <p>
+ * The {@link UIComponent} that is being encoded by this tag, if any.
+ * </p>
+ */
+ private UIComponent component = null;
- /** Value attribute value */
- protected Object rawItems; // our 'raw' items
+ /** Flag indicates if columns are already created */
+ private boolean created = false;
- /** End attribute - defines count of column if value attr hasn't been defined */
- private ValueExpression columns;
+ /** Iterator for columns's tag value attribute */
+ protected ForEachIterator items; // our 'digested' items
- /** Begin attribute - defines the first iteration item */
- private ValueExpression begin;
+ /** Value attribute value */
+ protected Object rawItems; // our 'raw' items
- /** Begin attribute - defines the last iteration item */
- private ValueExpression end;
+ /** End attribute - defines count of column if value attr hasn't been defined */
+ private ValueExpression columns;
- /** Index attr - defines page variable for current column counter */
- private ValueExpression _index;
+ /** Begin attribute - defines the first iteration item */
+ private ValueExpression begin;
- /** Var attr - defines page variable for current item */
- private String indexId;
+ /** Begin attribute - defines the last iteration item */
+ private ValueExpression end;
- /** Integer value of end attr. */
- private Integer _columns;
+ /** Index attr - defines page variable for current column counter */
+ private ValueExpression _index;
- /** Integer value of begin attr. */
- private Integer _begin;
+ /** Var attr - defines page variable for current item */
+ private String indexId;
- /** Integer value of end attr. */
- private Integer _end;
+ /** Integer value of end attr. */
+ private Integer _columns;
- /** String value of var attr */
- private String itemId = null;
+ /** Integer value of begin attr. */
+ private Integer _begin;
- /** Expression for var item */
- private IteratedExpression iteratedExpression;
+ /** Integer value of end attr. */
+ private Integer _end;
- /** Column incrementer */
- private Integer counter = 0;
+ /** String value of var attr */
+ private String itemId = null;
- /**
- * <p>
- * The <code>Lst</code> of {@link UIComponent} ids created or located by
- * nested {@link UIComponentTag}s while processing the current request.
- * </p>
- */
- // public List<String> createdComponents = null;
- /**
- * Caches the nearest enclosing {@link UIComponentRichClassicTagBase} of
- * this tag. This is used for duplicate id detection.
- */
- private UIComponentClassicTagBase parentTag = null;
+ /** Expression for var item */
+ private IteratedExpression iteratedExpression;
- /**
- * <p>
- * Return the {@link UIComponent} instance that is associated with this tag
- * instance. This method is designed to be used by tags nested within this
- * tag, and only returns useful results between the execution of
- * <code>doStartTag()</code> and <code>doEndTag()</code> on
this tag
- * instance.
- * </p>
- */
- public UIComponent getComponentInstance() {
+ /** Column incrementer */
+ private Integer counter = 0;
- return (this.component);
+ /**
+ * <p>
+ * The <code>Lst</code> of {@link UIComponent} ids created or located by
+ * nested {@link UIComponentTag}s while processing the current request.
+ * </p>
+ */
+ // public List<String> createdComponents = null;
+ /**
+ * Caches the nearest enclosing {@link UIComponentRichClassicTagBase} of
+ * this tag. This is used for duplicate id detection.
+ */
+ private UIComponentClassicTagBase parentTag = null;
- }
+ /**
+ * <p>
+ * Return the {@link UIComponent} instance that is associated with this tag
+ * instance. This method is designed to be used by tags nested within this
+ * tag, and only returns useful results between the execution of
+ * <code>doStartTag()</code> and <code>doEndTag()</code> on this
tag
+ * instance.
+ * </p>
+ */
+ public UIComponent getComponentInstance() {
- /**
- * <p>
- * The request scope attribute under which a component tag stack for the
- * current request will be maintained.
- * </p>
- */
- private static final String COMPONENT_TAG_STACK_ATTR =
"javax.faces.webapp.COMPONENT_TAG_STACK";
+ return (this.component);
- /**
- * <p>
- * The value binding expression (if any) used to wire up this component to a
- * {@link UIComponent} property of a JavaBean class.
- * </p>
- */
- private ValueExpression binding = null;
+ }
- /**
- * <p>
- * An override for the rendered attribute associated with our
- * {@link UIComponent}.
- * </p>
- */
- private ValueExpression rendered = null;
+ /**
+ * <p>
+ * The request scope attribute under which a component tag stack for the
+ * current request will be maintained.
+ * </p>
+ */
+ private static final String COMPONENT_TAG_STACK_ATTR =
"javax.faces.webapp.COMPONENT_TAG_STACK";
-
- /**
- * Dir attr
- */
- private ValueExpression _dir;
+ /**
+ * <p>
+ * The value binding expression (if any) used to wire up this component to a
+ * {@link UIComponent} property of a JavaBean class.
+ * </p>
+ */
+ private ValueExpression binding = null;
- /**
- * Sets dir attr
- * @param dir
- */
- public void setDir(ValueExpression dir) {
- _dir = dir;
- }
-
- /**
- * style CSS style(s) is/are to be applied when this component is rendered
- */
- private ValueExpression _style;
+ /**
+ * <p>
+ * An override for the rendered attribute associated with our
+ * {@link UIComponent}.
+ * </p>
+ */
+ private ValueExpression rendered = null;
- /**
- * CSS style(s) is/are to be applied when this component is rendered Setter
- * for style
- *
- * @param style -
- * new value
- */
- public void setStyle(ValueExpression __style) {
- this._style = __style;
- }
+ /**
+ * Dir attr
+ */
+ private ValueExpression _dir;
- /**
- * breakBefore if "true" next column begins from the first row
- */
- private ValueExpression _breakBefore;
+ /**
+ * Sets dir attr
+ *
+ * @param dir
+ */
+ public void setDir(ValueExpression dir) {
+ _dir = dir;
+ }
- /**
- * if "true" next column begins from the first row Setter for breakBefore
- *
- * @param breakBefore -
- * new value
- */
- public void setBreakBefore(ValueExpression __breakBefore) {
- this._breakBefore = __breakBefore;
- }
+ /**
+ * style CSS style(s) is/are to be applied when this component is rendered
+ */
+ private ValueExpression _style;
- /**
- * colspan Corresponds to the HTML colspan attribute
- */
- private ValueExpression _colspan;
+ /**
+ * CSS style(s) is/are to be applied when this component is rendered Setter
+ * for style
+ *
+ * @param style -
+ * new value
+ */
+ public void setStyle(ValueExpression __style) {
+ this._style = __style;
+ }
- /**
- * Corresponds to the HTML colspan attribute Setter for colspan
- *
- * @param colspan -
- * new value
- */
- public void setColspan(ValueExpression __colspan) {
- this._colspan = __colspan;
- }
+ /**
+ * breakBefore if "true" next column begins from the first row
+ */
+ private ValueExpression _breakBefore;
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.webapp.UIComponentClassicTagBase#createComponent(javax.faces.context.FacesContext,
- * java.lang.String)
- */
- @Override
- protected UIComponent createComponent(FacesContext context, String newId)
- throws JspException {
- // TODO Auto-generated method stub
- return context.getApplication().createComponent(COLUMN_COMPONENT_TYPE);
- }
+ /**
+ * if "true" next column begins from the first row Setter for breakBefore
+ *
+ * @param breakBefore -
+ * new value
+ */
+ public void setBreakBefore(ValueExpression __breakBefore) {
+ this._breakBefore = __breakBefore;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
- */
- @Override
- public String getComponentType() {
- // TODO Auto-generated method stub
- return null;
- }
+ /**
+ * colspan Corresponds to the HTML colspan attribute
+ */
+ private ValueExpression _colspan;
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
- */
- @Override
- public String getRendererType() {
- // TODO Auto-generated method stub
- return null;
- }
+ /**
+ * Corresponds to the HTML colspan attribute Setter for colspan
+ *
+ * @param colspan -
+ * new value
+ */
+ public void setColspan(ValueExpression __colspan) {
+ this._colspan = __colspan;
+ }
- /**
- * footerClass Space-separated list of CSS style class(es) that are be
- * applied to any footer generated for this table
- */
- private ValueExpression _footerClass;
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.webapp.UIComponentClassicTagBase#createComponent(javax.faces.context.FacesContext,
+ * java.lang.String)
+ */
+ @Override
+ protected UIComponent createComponent(FacesContext context, String newId)
+ throws JspException {
+ // TODO Auto-generated method stub
+ return context.getApplication().createComponent(COLUMN_COMPONENT_TYPE);
+ }
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * footer generated for this table Setter for footerClass
- *
- * @param footerClass -
- * new value
- */
- public void setFooterClass(ValueExpression __footerClass) {
- this._footerClass = __footerClass;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getComponentType()
+ */
+ @Override
+ public String getComponentType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * headerClass Space-separated list of CSS style class(es) that are be
- * applied to any header generated for this table
- */
- private ValueExpression _headerClass;
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentTagBase#getRendererType()
+ */
+ @Override
+ public String getRendererType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- /**
- * Space-separated list of CSS style class(es) that are be applied to any
- * header generated for this table Setter for headerClass
- *
- * @param headerClass -
- * new value
- */
- public void setHeaderClass(ValueExpression __headerClass) {
- this._headerClass = __headerClass;
- }
+ /**
+ * footerClass Space-separated list of CSS style class(es) that are be
+ * applied to any footer generated for this table
+ */
+ private ValueExpression _footerClass;
- /**
- * rowspan Corresponds to the HTML rowspan attribute
- */
- private ValueExpression _rowspan;
+ /**
+ * Space-separated list of CSS style class(es) that are be applied to any
+ * footer generated for this table Setter for footerClass
+ *
+ * @param footerClass -
+ * new value
+ */
+ public void setFooterClass(ValueExpression __footerClass) {
+ this._footerClass = __footerClass;
+ }
- /**
- * Corresponds to the HTML rowspan attribute Setter for rowspan
- *
- * @param rowspan -
- * new value
- */
- public void setRowspan(ValueExpression __rowspan) {
- this._rowspan = __rowspan;
- }
+ /**
+ * headerClass Space-separated list of CSS style class(es) that are be
+ * applied to any header generated for this table
+ */
+ private ValueExpression _headerClass;
- /**
- * sortExpression Attribute defines a bean property which is used for
- * sorting of a column
- */
- private ValueExpression _sortExpression;
+ /**
+ * Space-separated list of CSS style class(es) that are be applied to any
+ * header generated for this table Setter for headerClass
+ *
+ * @param headerClass -
+ * new value
+ */
+ public void setHeaderClass(ValueExpression __headerClass) {
+ this._headerClass = __headerClass;
+ }
- /**
- * Attribute defines a bean property which is used for sorting of a column
- * Setter for sortExpression
- *
- * @param sortExpression -
- * new value
- */
- public void setSortExpression(ValueExpression __sortExpression) {
- this._sortExpression = __sortExpression;
- }
+ /**
+ * rowspan Corresponds to the HTML rowspan attribute
+ */
+ private ValueExpression _rowspan;
- /**
- * sortable Boolean attribute. If "true" it's possible to sort the
column
- * content after click on the header. Default value is "true"
- */
- private ValueExpression _sortable;
+ /**
+ * Corresponds to the HTML rowspan attribute Setter for rowspan
+ *
+ * @param rowspan -
+ * new value
+ */
+ public void setRowspan(ValueExpression __rowspan) {
+ this._rowspan = __rowspan;
+ }
- /*
- * sortBy
+ /**
+ * sortExpression Attribute defines a bean property which is used for
+ * sorting of a column
+ */
+ private ValueExpression _sortExpression;
+
+ /**
* Attribute defines a bean property which is used for sorting of a column
+ * Setter for sortExpression
+ *
+ * @param sortExpression -
+ * new value
*/
+ public void setSortExpression(ValueExpression __sortExpression) {
+ this._sortExpression = __sortExpression;
+ }
+
+ /**
+ * sortable Boolean attribute. If "true" it's possible to sort the column
+ * content after click on the header. Default value is "true"
+ */
+ private ValueExpression _sortable;
+
+ /*
+ * sortBy Attribute defines a bean property which is used for sorting of a
+ * column
+ */
private ValueExpression _sortBy;
+
/**
* Attribute defines a bean property which is used for sorting of a column
* Setter for sortBy
- * @param sortBy - new value
+ *
+ * @param sortBy -
+ * new value
*/
- public void setSortBy( ValueExpression __sortBy ){
+ public void setSortBy(ValueExpression __sortBy) {
this._sortBy = __sortBy;
- }
+ }
- /**
- * sortOrder SortOrder is an enumeration of the possible sort orderings.
- */
- private ValueExpression _sortOrder;
+ /**
+ * sortOrder SortOrder is an enumeration of the possible sort orderings.
+ */
+ private ValueExpression _sortOrder;
- /**
- * SortOrder is an enumeration of the possible sort orderings. Setter for
- * sortOrder
- *
- * @param sortOrder -
- * new value
- */
- public void setSortOrder(ValueExpression __sortOrder) {
- this._sortOrder = __sortOrder;
- }
+ /**
+ * SortOrder is an enumeration of the possible sort orderings. Setter for
+ * sortOrder
+ *
+ * @param sortOrder -
+ * new value
+ */
+ public void setSortOrder(ValueExpression __sortOrder) {
+ this._sortOrder = __sortOrder;
+ }
- /**
- * selfSorted
- *
- */
- private ValueExpression _selfSorted;
+ /**
+ * selfSorted
+ *
+ */
+ private ValueExpression _selfSorted;
- /**
- *
- * Setter for selfSorted
- *
- * @param selfSorted -
- * new value
- */
- public void setSelfSorted(ValueExpression __selfSorted) {
- this._selfSorted = __selfSorted;
- }
+ /**
+ *
+ * Setter for selfSorted
+ *
+ * @param selfSorted -
+ * new value
+ */
+ public void setSelfSorted(ValueExpression __selfSorted) {
+ this._selfSorted = __selfSorted;
+ }
- /**
- * comparator
- *
- */
- private ValueExpression _comparator;
+ /**
+ * comparator
+ *
+ */
+ private ValueExpression _comparator;
- /**
- *
- * Setter for comparator
- *
- * @param comparator -
- * new value
- */
- public void setComparator(ValueExpression __comparator) {
- this._comparator = __comparator;
- }
+ /**
+ *
+ * Setter for comparator
+ *
+ * @param comparator -
+ * new value
+ */
+ public void setComparator(ValueExpression __comparator) {
+ this._comparator = __comparator;
+ }
/*
* filterBy
*
*/
private ValueExpression _filterBy;
+
/**
*
* Setter for filterBy
- * @param filterBy - new value
+ *
+ * @param filterBy -
+ * new value
*/
- public void setFilterBy( ValueExpression __filterBy ){
+ public void setFilterBy(ValueExpression __filterBy) {
this._filterBy = __filterBy;
- }
-
-
+ }
+
/*
* filterDefaultLabel
*
*/
private ValueExpression _filterDefaultLabel;
+
/**
*
* Setter for filterDefaultLabel
- * @param filterDefaultLabel - new value
+ *
+ * @param filterDefaultLabel -
+ * new value
*/
- public void setFilterDefaultLabel( ValueExpression __filterDefaultLabel ){
+ public void setFilterDefaultLabel(ValueExpression __filterDefaultLabel) {
this._filterDefaultLabel = __filterDefaultLabel;
- }
-
-
+ }
+
/*
- * filterEvent
- * Event for filter input that forces the filtration (default = onchange)
+ * filterEvent Event for filter input that forces the filtration (default =
+ * onchange)
*/
private ValueExpression _filterEvent;
+
/**
* Event for filter input that forces the filtration (default = onchange)
* Setter for filterEvent
- * @param filterEvent - new value
+ *
+ * @param filterEvent -
+ * new value
*/
- public void setFilterEvent( ValueExpression __filterEvent ){
+ public void setFilterEvent(ValueExpression __filterEvent) {
this._filterEvent = __filterEvent;
- }
-
-
+ }
+
/*
- * filterExpression
- * Attribute defines a bean property which is used for filtering of a column
+ * filterExpression Attribute defines a bean property which is used for
+ * filtering of a column
*/
private ValueExpression _filterExpression;
+
/**
* Attribute defines a bean property which is used for filtering of a column
* Setter for filterExpression
- * @param filterExpression - new value
+ *
+ * @param filterExpression -
+ * new value
*/
- public void setFilterExpression( ValueExpression __filterExpression ){
+ public void setFilterExpression(ValueExpression __filterExpression) {
this._filterExpression = __filterExpression;
- }
-
-
+ }
+
/*
* filterMethod
*
*/
private MethodExpression _filterMethod;
+
/**
*
* Setter for filterMethod
- * @param filterMethod - new value
+ *
+ * @param filterMethod -
+ * new value
*/
- public void setFilterMethod( MethodExpression __filterMethod ){
+ public void setFilterMethod(MethodExpression __filterMethod) {
this._filterMethod = __filterMethod;
- }
-
-
+ }
+
/*
* filterValue
*
*/
private ValueExpression _filterValue;
+
/**
*
* Setter for filterValue
- * @param filterValue - new value
+ *
+ * @param filterValue -
+ * new value
*/
- public void setFilterValue( ValueExpression __filterValue ){
+ public void setFilterValue(ValueExpression __filterValue) {
this._filterValue = __filterValue;
- }
+ }
- /**
- * Boolean attribute. If "true" it's possible to sort the column
content
- * after click on the header. Default value is "true" Setter for sortable
- *
- * @param sortable -
- * new value
- */
- public void setSortable(ValueExpression __sortable) {
- this._sortable = __sortable;
- }
+ /**
+ * Boolean attribute. If "true" it's possible to sort the column content
+ * after click on the header. Default value is "true" Setter for sortable
+ *
+ * @param sortable -
+ * new value
+ */
+ public void setSortable(ValueExpression __sortable) {
+ this._sortable = __sortable;
+ }
- /**
- * styleClass Corresponds to the HTML class attribute
- */
- private ValueExpression _styleClass;
+ /**
+ * styleClass Corresponds to the HTML class attribute
+ */
+ private ValueExpression _styleClass;
- /**
- * Corresponds to the HTML class attribute Setter for styleClass
- *
- * @param styleClass -
- * new value
- */
- public void setStyleClass(ValueExpression __styleClass) {
- this._styleClass = __styleClass;
- }
+ /**
+ * Corresponds to the HTML class attribute Setter for styleClass
+ *
+ * @param styleClass -
+ * new value
+ */
+ public void setStyleClass(ValueExpression __styleClass) {
+ this._styleClass = __styleClass;
+ }
- /**
- * value The current value for this component
- */
- private ValueExpression _value;
+ /**
+ * value The current value for this component
+ */
+ private ValueExpression _value;
- /**
- * The current value for this component Setter for value
- *
- * @param value -
- * new value
- */
- public void setValue(ValueExpression __value) {
- this._value = __value;
- }
+ /**
+ * The current value for this component Setter for value
+ *
+ * @param value -
+ * new value
+ */
+ public void setValue(ValueExpression __value) {
+ this._value = __value;
+ }
- /**
- * var A request-scope attribute via which the data object for the current
- * row will be used when iterating
- */
- private ValueExpression _var;
+ /**
+ * var A request-scope attribute via which the data object for the current
+ * row will be used when iterating
+ */
+ private ValueExpression _var;
- /**
- * A request-scope attribute via which the data object for the current row
- * will be used when iterating Setter for var
- *
- * @param var -
- * new value
- */
- public void setVar(ValueExpression __var) {
- this._var = __var;
- }
+ /**
+ * A request-scope attribute via which the data object for the current row
+ * will be used when iterating Setter for var
+ *
+ * @param var -
+ * new value
+ */
+ public void setVar(ValueExpression __var) {
+ this._var = __var;
+ }
- /*
- * width Attribute defines width of column. Default value is "100px".
- */
- private ValueExpression _width;
+ /*
+ * width Attribute defines width of column. Default value is "100px".
+ */
+ private ValueExpression _width;
- /**
- * Attribute defines width of column. Default value is "100px". Setter for
- * width
- *
- * @param width -
- * new value
- */
- public void setWidth(ValueExpression __width) {
- this._width = __width;
- }
+ /**
+ * Attribute defines width of column. Default value is "100px". Setter for
+ * width
+ *
+ * @param width -
+ * new value
+ */
+ public void setWidth(ValueExpression __width) {
+ this._width = __width;
+ }
- /**
- * Default constructor for AbstractColumnsTag class
- */
- public ColumnsTag() {
- super();
- }
+ /**
+ * Default constructor for AbstractColumnsTag class
+ */
+ public ColumnsTag() {
+ super();
+ }
- /**
- * <p>
- * Set an override for the rendered attribute.
- * </p>
- *
- * @param rendered
- * The new value for rendered attribute
- */
- public void setRendered(ValueExpression rendered) {
- this.rendered = rendered;
- }
+ /**
+ * <p>
+ * Set an override for the rendered attribute.
+ * </p>
+ *
+ * @param rendered
+ * The new value for rendered attribute
+ */
+ public void setRendered(ValueExpression rendered) {
+ this.rendered = rendered;
+ }
- /**
- * <p>
- * Set the value expression for our component.
- * </p>
- *
- * @param binding
- * The new value expression
- *
- * @throws JspException
- * if an error occurs
- */
- public void setBinding(ValueExpression binding) throws JspException {
- this.binding = binding;
- }
+ /**
+ * <p>
+ * Set the value expression for our component.
+ * </p>
+ *
+ * @param binding
+ * The new value expression
+ *
+ * @throws JspException
+ * if an error occurs
+ */
+ public void setBinding(ValueExpression binding) throws JspException {
+ this.binding = binding;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
- */
- @Override
- public int doAfterBody() throws JspException {
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
+ */
+ @Override
+ public int doAfterBody() throws JspException {
- if (hasNext()) {
- loop();
- } else
- return EVAL_BODY_INCLUDE;
+ if (hasNext()) {
+ exposeVariables();
+ loop();
+ } else
+ return EVAL_BODY_INCLUDE;
- exposeVariables();
+ exposeVariables();
- return EVAL_BODY_AGAIN;
- }
+ return EVAL_BODY_AGAIN;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#addFacet(java.lang.String)
- */
- protected void addFacet(String name) {
- super.addFacet(name);
+ /*
+ * (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.
- if (this.component != null && this.component.getFacets() != null) {
- Map<String, UIComponent> facets = this.component.getFacets();
- Iterator<UIComponent> it = facets.values().iterator();
- while (it.hasNext()) {
- super.addChild(it.next());
- }
+ // 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();
+ while (it.hasNext()) {
+ super.addChild(it.next());
+ }
+ }
}
- }
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doInitBody()
- */
- @Override
- public void doInitBody() throws JspException {
- // TODO Auto-generated method stub
- super.doInitBody();
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.jsp.tagext.BodyTagSupport#doInitBody()
+ */
+ @Override
+ public void doInitBody() throws JspException {
+ // TODO Auto-generated method stub
+ super.doInitBody();
- }
+ }
- /**
- * Removes any attributes that this LoopTagSupport set.
- *
- * <p>
- * These attributes are intended to support scripting variables with NESTED
- * scope, so we don't want to pollute attribute space by leaving them lying
- * around.
- */
- public void doFinally() {
- /*
- * Make sure to un-expose variables, restoring them to their prior
- * values, if applicable.
+ /**
+ * Removes any attributes that this LoopTagSupport set.
+ *
+ * <p>
+ * These attributes are intended to support scripting variables with NESTED
+ * scope, so we don't want to pollute attribute space by leaving them lying
+ * around.
*/
- unExposeVariables();
- }
+ public void doFinally() {
+ /*
+ * Make sure to un-expose variables, restoring them to their prior
+ * values, if applicable.
+ */
+ unExposeVariables();
+ }
- /**
- * Removes page attributes that we have exposed and, if applicable, restores
- * them to their prior values (and scopes).
- */
- private void unExposeVariables() {
- // "nested" variables are now simply removed
- if (itemId != null) {
- pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
- VariableMapper vm = pageContext.getELContext().getVariableMapper();
- if (vm != null)
- vm.setVariable(itemId, null);
+ /**
+ * Removes page attributes that we have exposed and, if applicable, restores
+ * them to their prior values (and scopes).
+ */
+ private void unExposeVariables() {
+ // "nested" variables are now simply removed
+ if (itemId != null) {
+ pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
+ VariableMapper vm = pageContext.getELContext().getVariableMapper();
+ if (vm != null)
+ vm.setVariable(itemId, null);
+ }
+ if (indexId != null) {
+ pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
+ VariableMapper vm = pageContext.getELContext().getVariableMapper();
+ if (vm != null)
+ vm.setVariable(indexId, null);
+ }
}
- if (indexId != null) {
- pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
- VariableMapper vm = pageContext.getELContext().getVariableMapper();
- if (vm != null)
- vm.setVariable(indexId, null);
+
+ /**
+ * Method is invoking by each iteration of body again rendering
+ *
+ * @throws JspTagException
+ */
+ private void loop() throws JspTagException {
+ if (!atFirst()) {
+ popUIComponentClassicTagBase();
+ }
+ UIComponent component = createColumn();
+ pushUIComponentClassicTagBase(this);
+
+ dataTable.getChildren().add(component);
+
+ next();
}
- }
- /**
- * Method is invoking by each iteration of body again rendering
- *
- * @throws JspTagException
- */
- private void loop() throws JspTagException {
- if (!atFirst()) {
- popUIComponentClassicTagBase();
+ private String generateColumnId() {
+ return COLUMN_ID_PREFIX + Integer.toString(counter++);
}
- UIComponent component = createColumn();
- pushUIComponentClassicTagBase(this);
- dataTable.getChildren().add(component);
+ /**
+ * Creates column instance
+ *
+ * @return
+ */
+ private UIComponent createColumn() {
+ UIComponent component = getFacesContext().getApplication()
+ .createComponent(COLUMN_COMPONENT_TYPE);
+ component.setId(generateColumnId());
- next();
- }
+ initColumnByThis(component);
- private String generateColumnId() {
- return COLUMN_ID_PREFIX + Integer.toString(counter++);
- }
+ this.component = component;
+ this.parentTag = getParentUIComponentClassicTagBase(pageContext);
- /**
- * Creates column instance
- *
- * @return
- */
- private UIComponent createColumn() {
- UIComponent component = getFacesContext().getApplication()
- .createComponent(COLUMN_COMPONENT_TYPE);
- component.setId(generateColumnId());
+ return component;
+ }
- initColumnByThis(component);
+ /**
+ * Inits column component by columns tag attrs
+ *
+ * @param column
+ */
+ void initColumnByThis(UIComponent column) {
- this.component = component;
- this.parentTag = getParentUIComponentClassicTagBase(pageContext);
+ ELContext elContext = getContext(getELContext());
+ Field[] fields = this.getClass().getDeclaredFields();
+ for (Field field : fields) {
+ try {
+ Object o = field.get(this);
+ if ((o != null) && (o instanceof ValueExpression)) {
+ String fieldName = field.getName();
+ String attributeName = fieldName.replace("_", "");
+ ValueExpression ex = (ValueExpression) o;
+ column.setValueExpression(attributeName,
+ createValueExpression(elContext, ex));
- return component;
- }
+ }
+ } catch (Exception e) {
+ continue;
+ }
+ }
+ }
- /**
- * 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("sortOrder", _sortOrder);
- column.setValueExpression("comparator", _comparator);
- column.setValueExpression("selfSorted", _selfSorted);
- column.setValueExpression("dir", _dir);
+ /**
+ * Creates value expression to be out into column
+ * @param context
+ * @param orig
+ * @return
+ */
+ private ValueExpression createValueExpression(ELContext context,
+ ValueExpression orig) {
+ ValueExpression vexpr = getFacesContext().getApplication()
+ .getExpressionFactory().createValueExpression(
+ getContext(context), orig.getExpressionString(),
+ orig.getExpectedType());
+ return vexpr;
+ }
- column.setValueExpression("filterBy", _filterBy);
- column.setValueExpression("filterDefaultLabel", _filterDefaultLabel);
- column.setValueExpression("filterEvent", _filterEvent);
- column.setValueExpression("filterExpression", _filterExpression);
- ((UIColumn)column).setFilterMethod(_filterMethod);
- column.setValueExpression("filterValue", _filterValue);
- column.setValueExpression("sortBy", _sortBy);
+ /**
+ * Create custom context with VariableMapper override.
+ * @param context
+ * @return
+ */
+ private ELContext getContext(final ELContext context) {
+ return new ELContext() {
- }
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return context.getELResolver();
+ }
- /**
- * Returns true if this is the first loop of columns tag
- *
- * @return
- */
- private boolean atFirst() {
- return (index == -1);
- }
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return context.getFunctionMapper();
+ }
- /**
- * Deletes dynamic rich columns created before
- */
- private void deleteRichColumns() {
- List<UIComponent> children = dataTable.getChildren();
- Iterator<UIComponent> it = children.iterator();
- List<UIComponent> forDelete = new ArrayList<UIComponent>();
- Integer i = 0;
- while (it.hasNext()) {
- UIComponent child = it.next();
- String id = child.getId();
- if (id != null && id.startsWith(COLUMN_ID_PREFIX)) {
- forDelete.add(child);
- }
- i++;
+ @Override
+ public VariableMapper getVariableMapper() {
+ return new VariableMapper() {
+
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ // TODO Auto-generated method stub
+ if (variable.equals(itemId)) {
+ return new IndexedValueExpression(_value, index + 1);
+ } else if (variable.equals(indexId)) {
+ return new IteratedIndexExpression(index + 1);
+ }
+ return context.getVariableMapper().resolveVariable(
+ variable);
+ }
+
+ @Override
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression) {
+ // TODO Auto-generated method stub
+ return context.getVariableMapper().setVariable(
+ variable, expression);
+ }
+
+ };
+ }
+
+ };
}
- it = forDelete.iterator();
- while (it.hasNext()) {
- UIComponent elem = it.next();
- children.remove(elem);
+
+ /**
+ * Returns true if this is the first loop of columns tag
+ *
+ * @return
+ */
+ private boolean atFirst() {
+ return (index == -1);
}
- }
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
- */
- @Override
- public int doStartTag() throws JspException {
+ /**
+ * Deletes dynamic rich columns created before
+ */
+ private void deleteRichColumns() {
+ List<UIComponent> children = dataTable.getChildren();
+ Iterator<UIComponent> it = children.iterator();
+ List<UIComponent> forDelete = new ArrayList<UIComponent>();
+ Integer i = 0;
+ while (it.hasNext()) {
+ UIComponent child = it.next();
+ String id = child.getId();
+ if (id != null && id.startsWith(COLUMN_ID_PREFIX)) {
+ forDelete.add(child);
+ }
+ i++;
+ }
+ it = forDelete.iterator();
+ while (it.hasNext()) {
+ UIComponent elem = it.next();
+ children.remove(elem);
+ }
+ }
- prepare();
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
+ */
+ @Override
+ public int doStartTag() throws JspException {
- if (created) {
- deleteRichColumns();
- created = false;
- }
+ prepare();
- // get the item we're interested in
- if (!hasNext()) {
- return SKIP_BODY;
+ if (created) {
+ deleteRichColumns();
+ created = false;
+ }
+
+ // get the item we're interested in
+ if (!hasNext()) {
+ return SKIP_BODY;
+ }
+
+ exposeVariables();
+
+ loop();
+
+ exposeVariables();
+
+ return EVAL_BODY_INCLUDE;
}
- loop();
+ /**
+ * Method prepares all we need for starting of tag rendering
+ *
+ * @throws JspTagException
+ */
+ private void prepare() throws JspTagException {
+ dataTable = getParentUIComponentClassicTagBase(pageContext)
+ .getComponentInstance();
+ created = (dataTable.getChildCount() > 0);
- exposeVariables();
+ initVariables();
- return EVAL_BODY_INCLUDE;
- }
+ // produce the right sort of ForEachIterator
+ if (_value != null) {
+ // If this is a deferred expression, make a note and get
+ // the 'items' instance.
+ if (_value instanceof ValueExpression) {
+ rawItems = _value.getValue(pageContext.getELContext());
+ }
+ // extract an iterator over the 'items' we've got
+ items = SimpleForEachIterator
+ .supportedTypeForEachIterator(rawItems);
+ } else {
+ // no 'items', so use 'begin' and 'end'
+ items = SimpleForEachIterator.beginEndForEachIterator(_columns - 1);
+ }
- /**
- * Method prepares all we need for starting of tag rendering
- *
- * @throws JspTagException
- */
- private void prepare() throws JspTagException {
- dataTable = getParentUIComponentClassicTagBase(pageContext)
- .getComponentInstance();
- created = (dataTable.getChildCount() > 0);
+ correctFirst();
- initVariables();
+ /*
+ * ResultSet no more supported in <c:forEach> // step must be 1 when
+ * ResultSet is passed in if (rawItems instanceof ResultSet && step !=
+ * 1) throw new JspTagException(
+ * Resources.getMessage("FOREACH_STEP_NO_RESULTSET"));
+ */
- // produce the right sort of ForEachIterator
- if (_value != null) {
- // If this is a deferred expression, make a note and get
- // the 'items' instance.
- if (_value instanceof ValueExpression) {
- rawItems = _value.getValue(pageContext.getELContext());
- }
- // extract an iterator over the 'items' we've got
- items = SimpleForEachIterator
- .supportedTypeForEachIterator(rawItems);
- } else {
- // no 'items', so use 'begin' and 'end'
- items = SimpleForEachIterator.beginEndForEachIterator(_columns - 1);
}
- correctFirst();
+ /**
+ * Extracts integer value from end attr
+ */
+ private void initColumnsCount() {
+ if (columns != null) {
+ if (columns instanceof ValueExpression)
+ try {
+ 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) {
+ _columns = 0;
+ }
+ } else {
+ _columns = 0;
+ }
+ }
- /*
- * ResultSet no more supported in <c:forEach> // step must be 1 when
- * ResultSet is passed in if (rawItems instanceof ResultSet && step !=
- * 1) throw new JspTagException(
- * Resources.getMessage("FOREACH_STEP_NO_RESULTSET"));
+ /**
+ * Extracts string value from var attr
*/
+ private void initVar() {
+ if (_var != null) {
+ try {
+ itemId = (String) _var.getValue(getELContext());
+ varPattern = Pattern.compile("[\\W]+" + itemId + "[\\W]+");
+ } catch (ClassCastException e) {
+ itemId = null;
+ }
- }
-
- /**
- * Extracts integer value from end attr
- */
- private void initColumnsCount() {
- if (columns != null) {
- if (columns instanceof ValueExpression)
- try {
- 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) {
- _columns = 0;
}
- } else {
- _columns = 0;
}
- }
- /**
- * Extracts string value from var attr
- */
- private void initVar() {
- if (_var != null) {
- try {
- itemId = (String) _var.getValue(getELContext());
- } catch (ClassCastException e) {
- itemId = null;
- }
+ /**
+ * Extracts string value from index attr
+ */
+ private void initIndex() {
+ if (_index != null) {
+ try {
+ indexId = (String) _index.getValue(getELContext());
+ indexPattern = Pattern.compile("[\\W]+" + indexId + "[\\W]+");
+ } catch (ClassCastException e) {
+ indexId = null;
+ }
+ }
}
- }
- /**
- * Extracts string value from index attr
- */
- private void initIndex() {
- if (_index != null) {
- try {
- indexId = (String) _index.getValue(getELContext());
- } catch (ClassCastException e) {
- indexId = null;
- }
+ /**
+ * 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 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;
+ /**
+ * 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;
+ }
+
}
- } catch (ClassCastException e) {
- _begin = 0;
- }
+ }
+ /**
+ * Extracts tags attributes values
+ */
+ private void initVariables() {
+ initColumnsCount();
+ initIndex();
+ initVar();
+ initBegin();
+ initEnd();
}
- }
- /**
- * 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;
+ /**
+ * Return true if we didn't complete column's count
+ *
+ * @return
+ * @throws JspTagException
+ */
+ private boolean hasNext() throws JspTagException {
+ if (_end != 0) {
+ return (index < (_end - 1)) ? items.hasNext() : false;
+ } else {
+ return items.hasNext();
}
- } catch (ClassCastException e) {
- _end = 0;
- }
+ }
+ /**
+ * Iterate to next column
+ *
+ * @return
+ * @throws JspTagException
+ */
+ private Object next() throws JspTagException {
+ Object o = items.next();
+ index++;
+ return o;
}
- }
- /**
- * Extracts tags attributes values
- */
- private void initVariables() {
- initColumnsCount();
- initIndex();
- initVar();
- initBegin();
- initEnd();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.jsp.tagext.BodyTagSupport#getBodyContent()
+ */
+ @Override
+ public BodyContent getBodyContent() {
+ // TODO Auto-generated method stub
+ return super.getBodyContent();
+ }
- /**
- * Return true if we didn't complete column's count
- *
- * @return
- * @throws JspTagException
- */
- private boolean hasNext() throws JspTagException {
- if (_end != 0) {
- return (index < (_end - 1)) ? items.hasNext() : false;
- } else {
- return items.hasNext();
+ /*
+ * (non-Javadoc)
+ *
+ * @see
javax.faces.webapp.UIComponentClassicTagBase#setProperties(javax.faces.component.UIComponent)
+ */
+ protected void setProperties(UIComponent component) {
+
}
- }
- /**
- * Iterate to next column
- *
- * @return
- * @throws JspTagException
- */
- private Object next() throws JspTagException {
- Object o = items.next();
- index++;
- return o;
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#hasBinding()
+ */
+ protected boolean hasBinding() {
+ return false;
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.servlet.jsp.tagext.BodyTagSupport#getBodyContent()
- */
- @Override
- public BodyContent getBodyContent() {
- // TODO Auto-generated method stub
- return super.getBodyContent();
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.webapp.UIComponentClassicTagBase#doEndTag()
+ */
+ @Override
+ public int doEndTag() throws JspException {
+ if (!atFirst()) {
+ popUIComponentClassicTagBase();
+ }
+ return EVAL_PAGE;
+ }
- /*
- * (non-Javadoc)
- *
- * @see
javax.faces.webapp.UIComponentClassicTagBase#setProperties(javax.faces.component.UIComponent)
- */
- protected void setProperties(UIComponent component) {
+ /**
+ * Sets page request variables
+ *
+ * @throws JspTagException
+ */
+ private void exposeVariables() throws JspTagException {
- }
+ /*
+ * We need to support null items returned from next(); we do this simply
+ * by passing such non-items through to the scoped variable as
+ * effectively 'null' (that is, by calling removeAttribute()).
+ *
+ * Also, just to be defensive, we handle the case of a null 'status'
+ * object as well.
+ *
+ * We call getCurrent() and getLoopStatus() (instead of just using
+ * 'item' and 'status') to bridge to subclasses correctly. A subclass
+ * can override getCurrent() or getLoopStatus() but still depend on our
+ * doStartTag() and doAfterBody(), which call this method
+ * (exposeVariables()), to expose 'item' and 'status' correctly.
+ */
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#hasBinding()
- */
- protected boolean hasBinding() {
- return false;
- }
+ // Set up var variable
+ if (itemId != null) {
+ if (index == null)
+ pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
+ else if (_value != null) {
+ VariableMapper vm = // getFacesContext().getELContext().getVariableMapper();
+ pageContext.getELContext().getVariableMapper();
+ if (vm != null) {
+ ValueExpression ve = getVarExpression(_value);
+ vm.setVariable(itemId, ve);
+ getELContext().getVariableMapper().setVariable(itemId, ve);
+ }
+ } else
+ pageContext.setAttribute(itemId, index);
+ }
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.webapp.UIComponentClassicTagBase#doEndTag()
- */
- @Override
- public int doEndTag() throws JspException {
- if (!atFirst()) {
- popUIComponentClassicTagBase();
+ // Set up index variable
+
+ if (indexId != null) {
+ if (index == null)
+ pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
+ else {
+ IteratedIndexExpression indexExpression = new IteratedIndexExpression(
+ index - _begin);
+ VariableMapper vm = pageContext.getELContext()
+ .getVariableMapper();
+ if (vm != null) {
+ vm.setVariable(indexId, indexExpression);
+ getELContext().getVariableMapper().setVariable(indexId,
+ indexExpression);
+ }
+ pageContext.setAttribute(indexId, index - _begin);
+ }
+ }
+
}
- return EVAL_PAGE;
- }
- /**
- * Sets page request variables
- *
- * @throws JspTagException
- */
- private void exposeVariables() throws JspTagException {
+ @Override
+ public void setPageContext(PageContext pageContext) {
+ super.setPageContext(pageContext);
+ }
- /*
- * We need to support null items returned from next(); we do this simply
- * by passing such non-items through to the scoped variable as
- * effectively 'null' (that is, by calling removeAttribute()).
+ /**
+ * Return expression for page variables
*
- * Also, just to be defensive, we handle the case of a null 'status'
- * object as well.
- *
- * We call getCurrent() and getLoopStatus() (instead of just using
- * 'item' and 'status') to bridge to subclasses correctly. A subclass
- * can override getCurrent() or getLoopStatus() but still depend on our
- * doStartTag() and doAfterBody(), which call this method
- * (exposeVariables()), to expose 'item' and 'status' correctly.
+ * @param expr
+ * @return
*/
+ private ValueExpression getVarExpression(ValueExpression expr) {
+ Object o = expr.getValue(pageContext.getELContext());
+ if (o.getClass().isArray() || o instanceof List) {
+ return new IndexedValueExpression(_value, index);
+ }
- // Set up var variable
- if (itemId != null) {
- if (index == null)
- pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
- else if (_value != null) {
- VariableMapper vm = pageContext.getELContext()
- .getVariableMapper();
- if (vm != null) {
- ValueExpression ve = getVarExpression(_value);
- vm.setVariable(itemId, ve);
+ if (o instanceof Collection || o instanceof Iterator
+ || o instanceof Enumeration || o instanceof Map
+ || o instanceof String) {
+
+ if (iteratedExpression == null) {
+ iteratedExpression = new IteratedExpression(_value, getDelims());
+ }
+ return new IteratedValueExpression(iteratedExpression, index);
}
- } else
- pageContext.setAttribute(itemId, index);
+
+ throw new ELException("FOREACH_BAD_ITEMS");
}
- // Set up index variable
+ /*
+ * Get the delimiter for string tokens. Used only for constructing the
+ * deferred expression for it.
+ */
+ protected String getDelims() {
+ return ",";
+ }
- if (indexId != null) {
- if (index == null)
- pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
- else {
- IteratedIndexExpression indexExpression = new IteratedIndexExpression(
- index - _begin);
- VariableMapper vm = pageContext.getELContext()
- .getVariableMapper();
- if (vm != null) {
- vm.setVariable(indexId, indexExpression);
+ /**
+ * 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
}
- pageContext.setAttribute(indexId, index - _begin);
- }
}
- }
+ /**
+ * <p>
+ * Pop the top {@link UIComponentTag} instance off of our component tag
+ * stack, deleting the stack if this was the last entry.
+ * </p>
+ */
+ private void popUIComponentClassicTagBase() {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ List list = (List) requestMap.get(COMPONENT_TAG_STACK_ATTR);
+ if (list != null) {
+ list.remove(list.size() - 1);
+ if (list.size() < 1) {
+ requestMap.remove(COMPONENT_TAG_STACK_ATTR);
+ }
+ }
- /**
- * Return expression for page variables
- *
- * @param expr
- * @return
- */
- private ValueExpression getVarExpression(ValueExpression expr) {
- Object o = expr.getValue(pageContext.getELContext());
- if (o.getClass().isArray() || o instanceof List) {
- return new IndexedValueExpression(_value, index);
}
- if (o instanceof Collection || o instanceof Iterator
- || o instanceof Enumeration || o instanceof Map
- || o instanceof String) {
+ /**
+ * <p>
+ * Push the specified {@link UIComponentTag} instance onto our component tag
+ * stack, creating a stack if necessary.
+ * </p>
+ */
+ private void pushUIComponentClassicTagBase(UIComponentClassicTagBase tag) {
+ FacesContext context = FacesContext.getCurrentInstance();
+ Map<String, Object> requestMap = context.getExternalContext()
+ .getRequestMap();
+ List<UIComponentClassicTagBase> list = TypedCollections
+ .dynamicallyCastList((List) requestMap
+ .get(COMPONENT_TAG_STACK_ATTR),
+ UIComponentClassicTagBase.class);
+ if (list == null) {
+ // noinspection CollectionWithoutInitialCapacity
+ list = new ArrayList<UIComponentClassicTagBase>();
+ requestMap.put(COMPONENT_TAG_STACK_ATTR, list);
+ }
+ list.add(tag);
- if (iteratedExpression == null) {
- iteratedExpression = new IteratedExpression(_value, getDelims());
- }
- return new IteratedValueExpression(iteratedExpression, index);
}
- throw new ELException("FOREACH_BAD_ITEMS");
- }
+ /**
+ * @return the begin
+ */
+ public ValueExpression getBegin() {
+ return begin;
+ }
- /*
- * Get the delimiter for string tokens. Used only for constructing the
- * deferred expression for it.
- */
- protected String getDelims() {
- return ",";
- }
+ /**
+ * @param begin
+ * the begin to set
+ */
+ public void setBegin(ValueExpression begin) {
+ this.begin = begin;
+ }
- /**
- * 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
+ /**
+ * @return the columns
+ */
+ public ValueExpression getColumns() {
+ return columns;
}
- }
- /**
- * <p>
- * Pop the top {@link UIComponentTag} instance off of our component tag
- * stack, deleting the stack if this was the last entry.
- * </p>
- */
- private void popUIComponentClassicTagBase() {
- FacesContext context = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- List list = (List) requestMap.get(COMPONENT_TAG_STACK_ATTR);
- if (list != null) {
- list.remove(list.size() - 1);
- if (list.size() < 1) {
- requestMap.remove(COMPONENT_TAG_STACK_ATTR);
- }
+ /**
+ * @param columns
+ * the columns to set
+ */
+ public void setColumns(ValueExpression columns) {
+ this.columns = columns;
}
- }
+ /**
+ * @return the index
+ */
+ public ValueExpression getIndex() {
+ return _index;
+ }
- /**
- * <p>
- * Push the specified {@link UIComponentTag} instance onto our component tag
- * stack, creating a stack if necessary.
- * </p>
- */
- private void pushUIComponentClassicTagBase(UIComponentClassicTagBase tag) {
- FacesContext context = FacesContext.getCurrentInstance();
- Map<String, Object> requestMap = context.getExternalContext()
- .getRequestMap();
- List<UIComponentClassicTagBase> list = TypedCollections
- .dynamicallyCastList((List) requestMap
- .get(COMPONENT_TAG_STACK_ATTR),
- UIComponentClassicTagBase.class);
- if (list == null) {
- // noinspection CollectionWithoutInitialCapacity
- list = new ArrayList<UIComponentClassicTagBase>();
- requestMap.put(COMPONENT_TAG_STACK_ATTR, list);
+ /**
+ * @param index
+ * the index to set
+ */
+ public void setIndex(ValueExpression index) {
+ this._index = index;
}
- list.add(tag);
- }
+ /**
+ * @return the end
+ */
+ public ValueExpression getEnd() {
+ return end;
+ }
- /**
- * @return the begin
- */
- public ValueExpression getBegin() {
- return begin;
- }
+ /**
+ * @param end
+ * the end to set
+ */
+ public void setEnd(ValueExpression end) {
+ this.end = end;
+ }
- /**
- * @param begin
- * the begin to set
- */
- public void setBegin(ValueExpression begin) {
- this.begin = begin;
- }
+}
- /**
- * @return the columns
- */
- public ValueExpression getColumns() {
- return columns;
- }
+class ELContextWraper extends ELContext {
- /**
- * @param columns
- * the columns to set
- */
- public void setColumns(ValueExpression columns) {
- this.columns = columns;
- }
+ VariableMapper vm;
- /**
- * @return the index
- */
- public ValueExpression getIndex() {
- return _index;
- }
+ public ELContextWraper() {
+ // TODO Auto-generated constructor stub
+ }
- /**
- * @param index
- * the index to set
- */
- public void setIndex(ValueExpression index) {
- this._index = index;
- }
+ public ELContextWraper(ELResolver resolver) {
- /**
- * @return the end
- */
- public ValueExpression getEnd() {
- return end;
- }
+ }
- /**
- * @param end
- * the end to set
- */
- public void setEnd(ValueExpression end) {
- this.end = end;
- }
+ @Override
+ public VariableMapper getVariableMapper() {
+ // TODO Auto-generated method stub
+ return vm;
+ }
+ @Override
+ public ELResolver getELResolver() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+};
+
+class VariableWraper extends VariableMapper {
+
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
+
+class ValueExpressioWraper extends ValueExpression {
+
+ ValueExpression expression;
+
+ ValueExpression value;
+
+ // Object value;
+
+ int i = 0;
+
+ public ValueExpressioWraper(ValueExpression e, ValueExpression v) {
+ expression = e;
+ value = v;
+ }
+
+ private ELContext createElContext(final ELContext arg0) {
+ return new ELContext() {
+
+ @Override
+ public Object getContext(Class key) {
+ // TODO Auto-generated method stub
+ return arg0.getContext(key);
+ }
+
+ @Override
+ public ELResolver getELResolver() {
+ return arg0.getELResolver();
+ }
+
+ @Override
+ public FunctionMapper getFunctionMapper() {
+ return arg0.getFunctionMapper();
+ }
+
+ @Override
+ public VariableMapper getVariableMapper() {
+ // return arg0.getVariableMapper();
+ return new VariableMapper() {
+
+ @Override
+ public ValueExpression resolveVariable(String variable) {
+ if ("col".equals(variable)) {
+ return value;
+ } else {
+ return arg0.getVariableMapper().resolveVariable(
+ variable);
+ }
+ }
+
+ @Override
+ public ValueExpression setVariable(String variable,
+ ValueExpression expression) {
+ return arg0.getVariableMapper().setVariable(variable,
+ expression);
+ }
+
+ };
+ // return arg0.getVariableMapper();
+ }
+
+ };
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getExpectedType()
+ */
+ @Override
+ public Class<?> getExpectedType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<?> getType(ELContext arg0) throws NullPointerException,
+ PropertyNotFoundException, ELException {
+ return expression.getType(arg0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#getValue(javax.el.ELContext)
+ */
+ @Override
+ public Object getValue(ELContext context) {
+ ELContext context2 = createElContext(context);
+ ValueExpression variable = context.getVariableMapper().resolveVariable(
+ "col");
+ // context2.getVariableMapper().setVariable("col", value);
+ try {
+ return expression.getValue(context2);
+ } finally {
+ // context2.getVariableMapper().setVariable("col", variable);
+ }
+ // return expression.getValue(createElContext(context));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#isReadOnly(javax.el.ELContext)
+ */
+ @Override
+ public boolean isReadOnly(ELContext context) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.ValueExpression#setValue(javax.el.ELContext,
+ * java.lang.Object)
+ */
+ @Override
+ public void setValue(ELContext context, Object value) {
+ expression.setValue(context, value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#getExpressionString()
+ */
+ @Override
+ public String getExpressionString() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.el.Expression#isLiteralText()
+ */
+ @Override
+ public boolean isLiteralText() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
\ No newline at end of file