Author: ekoneil
Date: Thu Apr 21 12:17:04 2005
New Revision: 164107
URL: http://svn.apache.org/viewcvs?rev=164107&view=rev
Log:
Cleanup in the repeater before fixing JIRA 481.
BB: self
DRT: NetUI pass
BVT: NetUI pass
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/CellRepeater.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/Repeater.java
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/PadContext.java
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/CellRepeater.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/CellRepeater.java?rev=164107&r1=164106&r2=164107&view=diff
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/CellRepeater.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/cellrepeater/CellRepeater.java
Thu Apr 21 12:17:04 2005
@@ -581,9 +581,6 @@
write(_sb.toString());
}
- DataAccessProviderStack.removeDataAccessProvider(pageContext);
- _containerInPageContext = false;
-
return EVAL_PAGE;
}
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/Repeater.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/Repeater.java?rev=164107&r1=164106&r2=164107&view=diff
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/Repeater.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/Repeater.java
Thu Apr 21 12:17:04 2005
@@ -21,6 +21,7 @@
import javax.servlet.jsp.tagext.*;
import java.util.Iterator;
import java.util.List;
+import java.util.Collections;
import org.apache.beehive.netui.script.common.DataAccessProviderStack;
import org.apache.beehive.netui.script.common.IDataAccessProvider;
@@ -53,7 +54,7 @@
* of the current "customer" in the data set.</p>
* <pre>
* <ul>
- * <netui-data:repeater dataSource="{pageFlow.customers}">
+ * <netui-data:repeater dataSource="{pageInput.customers}">
* <li><netui:label value="{container.item.lastName},
{container.item.firstName}"/></li>
* </netui-data:repeater>
* </ul>
@@ -67,7 +68,7 @@
* shown above, but it uses the structured tags for rendering the
* <code>{pageFlow.customers}</code> expression:</p>
* <pre>
- * <netui-data:repeater dataSource="{pageFlow.customers}">
+ * <netui-data:repeater dataSource="{pageInput.customers}">
* <netui-data:repeaterHeader>
* <ul>
* </netui-data:repeaterHeader>
@@ -103,7 +104,7 @@
* render the items in the "customers" data set as an unordered HTML list.</p>
* <p/>
* <pre> <ul>
- * <netui-data:repeater dataSource="{pageFlow.customers}">
+ * <netui-data:repeater dataSource="{pageInput.customers}">
* <li><netui:label value="{container.item.lastName},
{container.item.firstName}"/></li>
* </netui-data:repeater>
* </ul></pre>
@@ -119,7 +120,7 @@
* HTML markup:</p>
* <p/>
* <pre>
- * <netui-data:repeater dataSource="{pageFlow.customers}">
+ * <netui-data:repeater dataSource="{pageInput.customers}">
* <netui-data:repeaterHeader>
* <ul>
* </netui-data:repeaterHeader>
@@ -133,7 +134,7 @@
* @example The following sample renders the data set as an HTML table. The
table has two columns, "index" and "name",
* and each iteration over the data set is rendered as a row of the table.
* <p/>
- * <pre> <netui-data:repeater dataSource="{pageFlow.myDataSet}">
+ * <pre> <netui-data:repeater dataSource="{pageInput.myDataSet}">
* <netui-data:repeaterHeader>
* <table border="1">
* <tr>
@@ -156,9 +157,8 @@
* </netui-data:repeaterFooter>
* </netui-data:repeater></pre>
* @netui:tag name="repeater" description="A markup-generic tag that repeats
over a data set, and renders the data onto the page."
- * @netui.tldx:tag whitespace="indent"
- *
expressioninfo="workshop.netui.jspdesigner.tldx.expression.NetuiContainerExpressionInfo"
- * renderer="workshop.netui.jspdesigner.tldx.RepeaterRenderer"
+ * @netui.tldx:tag whitespace="indent"
expressioninfo="workshop.netui.jspdesigner.tldx.expression.NetuiContainerExpressionInfo"
+ * renderer="workshop.netui.jspdesigner.tldx.RepeaterRenderer"
*/
public class Repeater
extends AbstractClassicTag
@@ -197,15 +197,16 @@
private boolean _ignoreNulls = false;
private boolean _haveKids = false;
+ private boolean _containerInPageContext = false;
private int _currentIndex = -1;
private int _renderedItems = 0;
private int _renderState = INIT;
private Object _defaultText = null;
private Object _currentItem = null;
+ private String _dataSource = null;
private Iterator _iterator = null;
private PadContext _padContext = null;
private InternalStringBuilder _contentBuffer = null;
- private String _dataSource = null;
/**
* Get the name of this tag. This is used to identify the type of this tag
@@ -355,10 +356,7 @@
*/
public int doStartTag()
throws JspException {
- Object source = null;
-
- if(getDataSource() != null)
- source = evaluateDataSource();
+ Object source = evaluateDataSource();
// report any errors that may have occured
if(hasErrors())
@@ -370,77 +368,75 @@
if(source != null) {
_iterator = IteratorFactory.createIterator(source);
if(_iterator == null) {
- String msg = Bundle.getString("Tags_Repeater_nullIterator");
- if(LOGGER.isWarnEnabled()) LOGGER.warn(msg);
- _iterator = IteratorFactory.EMPTY_ITERATOR;
+ LOGGER.warn(Bundle.getString("Tags_Repeater_nullIterator"));
+ _iterator = Collections.EMPTY_LIST.iterator();
}
- // report any errors that may have occured
- if(hasErrors())
- return SKIP_BODY;
-
- if(_iterator != null && _iterator.hasNext()) {
+ if(_iterator.hasNext()) {
_currentIndex = 0;
_currentItem = _iterator.next();
if(_ignoreNulls && _currentItem == null) {
- // doStartTag doesn't know if the repeater is structured
or unstructured
- // thus, if ignoreNulls is true, it's go to make an
attempt to go
- // through the body with a non-null item. if there are no
non-null
- // items in the data structure, the doAfterBody method
will handle
- // this correctly, but a data structure with a null first
item
- // will render the same as a data structure with a null
second item
+ /*
+ doStartTag doesn't know if the repeater is structured or
unstructured
+ thus, if ignoreNulls is true, it's going to make an
attempt to go
+ through the body with a non-null item. if there are no
non-null
+ items in the data structure, the doAfterBody method will
handle
+ this correctly, but a data structure with a null first
item
+ will render the same as a data structure with a null
second item
+ */
advanceToNonNullItem();
- // currentItem may be null here
-
+ /*
+ this null check needs to re-run here because the
advanceToNonNullItem method
+ side-effects the _currentItem.
+ */
if(_currentItem == null)
empty = true;
}
}
- // there is no data set of there are zero items in the iterator
- else if(_iterator == null || !_iterator.hasNext())
- empty = true;
+ /* there is no data set of there are zero items in the iterator */
+ else empty = true;
}
- // the dataSource evaluated to null
- else
+ /* the dataSource evaluated to null */
+ else {
+ _iterator = Collections.EMPTY_LIST.iterator();
empty = true;
-
- // TODO: optimize -- this doesn't need to happen when the data set is
empty
- DataAccessProviderStack.addDataAccessProvider(this, pageContext);
+ }
if(empty) {
- // if the defaultText attribute is non-null, it will be evaluated
as an expression
- // and rendered to the page
- if(_defaultText != null) {
+ /* if the defaultText attribute is non-null, it will be evaluated
as an expression and rendered to the page */
+ if(_defaultText != null)
addContent(_defaultText.toString());
- }
-
- // the data Iterator was either empty or contained zero non-null
items (if _ignoreNulls=true)
- // skip the body and go straight to doEndTag
return SKIP_BODY;
}
- else
+ else {
+ DataAccessProviderStack.addDataAccessProvider(this, pageContext);
+ _containerInPageContext = true;
return EVAL_BODY_BUFFERED;
+ }
}
/**
* @return SKIP_BODY if an error occurs or the data set has been rendered;
EVAL_BODY_AGAIN otherwise
*/
public int doAfterBody() {
+
if(hasErrors())
return SKIP_BODY;
- boolean kids = _haveKids;
+ LOGGER.debug("structured repeater: " + _haveKids + " render state: " +
renderStateToString(_renderState));
- if(LOGGER.isDebugEnabled()) LOGGER.debug("structured repeater: " +
kids + " render state: " + renderStateToString(_renderState));
-
- // structured rendering of the repeater; body content is ignored and
real
- // content is rendered through cooperating nested tags
- if(kids)
+ /*
+ structured rendering of the repeater; body content is ignored and
real
+ content is rendered through cooperating nested tags
+ */
+ if(_haveKids)
return renderStructured();
- // unstructured rendering of the repeater; this means that there isn't
- // a repeater(Header|Item|Footer) inside the body of the repeater.
+ /*
+ unstructured rendering of the repeater; this means that there isn't
+ a repeater(Header|Item|Footer) inside the body of the repeater.
+ */
else {
if(bodyContent != null) {
addContent(bodyContent.getString());
@@ -454,16 +450,16 @@
if(_ignoreNulls && _currentItem == null) {
advanceToNonNullItem();
- // ignoring null items and no more non-null items, so skip
to doEndTag()
- if(_currentItem == null) return SKIP_BODY;
+ /* ignoring null items and no more non-null items, so skip
to doEndTag() */
+ if(_currentItem == null)
+ return SKIP_BODY;
}
- // found another item; re-render the repeater's body
+ /* found another item; re-render the repeater's body */
return EVAL_BODY_AGAIN;
}
- // no more items; skip to doEndTag()
- else
- return SKIP_BODY;
+ /* no more items; skip to doEndTag() */
+ else return SKIP_BODY;
}
}
@@ -473,13 +469,12 @@
*/
public int doEndTag()
throws JspException {
+
if(hasErrors())
reportErrors();
else if(_contentBuffer != null)
write(_contentBuffer.toString());
- DataAccessProviderStack.removeDataAccessProvider(pageContext);
-
return EVAL_PAGE;
}
@@ -507,6 +502,10 @@
_padContext = null;
_ignoreNulls = false;
_renderedItems = 0;
+ if(_containerInPageContext) {
+ DataAccessProviderStack.removeDataAccessProvider(pageContext);
+ _containerInPageContext = false;
+ }
}
/**
@@ -518,7 +517,7 @@
*
* @return EVAL_BODY_AGAIN unless the lifecycle has completed; then return
SKIP_BODY
*/
- // TODO: optimize the number of trips through the body by ignoring the
header / footer when necessary
+ /* todo: perf -- optimize the number of trips through the body by ignoring
the header / footer when necessary */
private int renderStructured() {
if(LOGGER.isDebugEnabled() && _padContext != null)
LOGGER.debug("\ncurrentIndex: " + _currentIndex + "\n" +
@@ -531,12 +530,9 @@
}
if(_renderState == HEADER) {
- // This assert is invalid because adanceToNonNullItem is called in
the
- // doStartTag() method and may move the _currentIndex beyond 0
- //assert (_currentIndex == 0) : "Unexpected index value:" +
_currentIndex;
assert _renderedItems == 0;
- // this would only happen if Pad.maxRepeat == 0
+ /* this would only happen if Pad.maxRepeat == 0 */
if(_padContext != null &&
_padContext.checkMaxRepeat(_renderedItems)) {
_renderState = FOOTER;
return EVAL_BODY_AGAIN;
@@ -544,20 +540,18 @@
if(_currentItem == null && _ignoreNulls) {
advanceToNonNullItem();
-
- // no non-null item was found; render the footer
+
+ /* no non-null item was found; render the footer */
if(_currentItem == null) {
doPadding();
// render the header
_renderState = FOOTER;
}
- // non-null item found; it's not the 0th item; render it
- else
- _renderState = ITEM;
+ /* non-null item found; it's not the 0th item; render it */
+ else _renderState = ITEM;
}
- // 0th item is non-null; render it
- else
- _renderState = ITEM;
+ /* 0th item is non-null; render it */
+ else _renderState = ITEM;
return EVAL_BODY_AGAIN;
}
@@ -565,38 +559,35 @@
if(_renderState == ITEM) {
_renderedItems++;
- if(LOGGER.isDebugEnabled() && _padContext != null)
- LOGGER.debug("\ncurrentIndex: " + _currentIndex + "\n" +
- "checkMaxRepeat: " +
_padContext.checkMaxRepeat(_currentIndex) + "\n" +
- "checkMinRepeat: " +
_padContext.checkMinRepeat(_currentIndex) + "\n");
-
- // check that the maximum number of items to render has _not_ been
reached
- if(_iterator.hasNext() && (_padContext == null || (_padContext !=
null && !_padContext.checkMaxRepeat(_renderedItems)))) {
+ /* check that the maximum number of items to render has *not* been
reached */
+ if(_iterator.hasNext() && (_padContext == null || (_padContext
!= null && !_padContext.checkMaxRepeat(_renderedItems)))) {
_currentIndex++;
_currentItem = _iterator.next();
if(_ignoreNulls && _currentItem == null) {
advanceToNonNullItem();
-
- // last item
+
+ /* last item */
if(_currentItem == null) {
doPadding();
- // render the header
+ /* render the header */
_renderState = FOOTER;
return EVAL_BODY_AGAIN;
}
}
- // if _ignoreNulls == false, the _currentItem may be null here
+ /* if _ignoreNulls is false, the _currentItem may be null here
*/
return EVAL_BODY_AGAIN;
}
- // have finished rendering items for some reason:
- // 1) there isn't a next item
- // 2) reached the maximum number of items to render
- // So:
- // 1) pad if necessary
- // 2) render the footer
+ /*
+ have finished rendering items for some reason:
+ 1) there isn't a next item
+ 2) reached the maximum number of items to render
+ So:
+ 1) pad if necessary
+ 2) render the footer
+ */
else {
doPadding();
@@ -653,8 +644,10 @@
*/
private final void doPadding() {
if(_padContext != null && !_padContext.checkMinRepeat(_renderedItems))
{
- // since padding is now running, un-set the current item so that
the last
- // item isn't accessible during any later data binding
+ /*
+ since padding is now running, un-set the current item so that
the last
+ item isn't accessible during any later data binding
+ */
_currentItem = null;
for(int i = _renderedItems; !_padContext.checkMinRepeat(i); i++) {
@@ -753,8 +746,7 @@
if (ds == null)
return null;
- // have a valid expression
- Object o = expr.evaluateExpression(dataSource, "dataSource",
pageContext);
- return o;
+ /* have a valid expression */
+ return expr.evaluateExpression(dataSource, "dataSource", pageContext);
}
}
Modified:
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/PadContext.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/PadContext.java?rev=164107&r1=164106&r2=164107&view=diff
==============================================================================
---
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/PadContext.java
(original)
+++
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/repeater/pad/PadContext.java
Thu Apr 21 12:17:04 2005
@@ -85,8 +85,7 @@
return true;
else if(currCount >= _minRepeat)
return true;
- else
- return false;
+ else return false;
}
/**
@@ -98,8 +97,7 @@
return false;
else if(currCount < _maxRepeat)
return false;
- else
- return true;
+ else return true;
}
/**
@@ -113,7 +111,6 @@
buf.append("padText: " + _padText + "\n");
buf.append("minRepeat: " + _minRepeat + "\n");
buf.append("maxRepeat: " + _maxRepeat + "\n");
-
return buf.toString();
}
}