下面列出了javax.servlet.jsp.tagext.BodyTagSupport#EVAL_BODY_AGAIN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* ${@inheritDoc}
*/
@Override
public int doAfterBody() throws JspException {
int retval = BodyTagSupport.EVAL_BODY_AGAIN;
ListCommand nextCmd = getNextCommand();
switch (nextCmd) {
case TBL_HEADING: doAfterBodyRenderListBegin(); break;
case TBL_ADDONS: doAfterBodyRenderTopAddons(); break;
case COL_HEADER: doAfterBodyRenderColHeaders(); break;
case BEFORE_RENDER: retval = doAfterBodyRenderBeforeData(); break;
case RENDER: retval = doAfterBodyRenderData(); break;
case AFTER_RENDER: retval = doAfterBodyRenderAfterData(); break;
case TBL_FOOTER: retval = doAfterBodyRenderFooterAddons(); break;
default: break;
}
return retval;
}
/**
* ${@inheritDoc}
*/
@Override
public int doAfterBody() throws JspException {
int retval = BodyTagSupport.EVAL_BODY_AGAIN;
ListCommand nextCmd = getNextCommand();
switch (nextCmd) {
case TBL_HEADING: doAfterBodyRenderListBegin(); break;
case TBL_ADDONS: doAfterBodyRenderTopAddons(); break;
case COL_HEADER: doAfterBodyRenderColHeaders(); break;
case BEFORE_RENDER: retval = doAfterBodyRenderBeforeData(); break;
case RENDER: retval = doAfterBodyRenderData(); break;
case AFTER_RENDER: retval = doAfterBodyRenderAfterData(); break;
case TBL_FOOTER: retval = doAfterBodyRenderFooterAddons(); break;
default: break;
}
return retval;
}
private int doAfterBodyRenderData() throws JspException {
// if there was a previous object, close its row
if (currentObject != null) {
ListTagUtil.write(pageContext, "</tr>");
}
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.RENDER);
if (iterator.hasNext()) {
Object obj = iterator.next();
if (RhnListTagFunctions.isExpandable(obj)) {
parentObject = obj;
}
currentObject = obj;
}
else {
currentObject = null;
}
if (currentObject != null) {
ListTagUtil.write(pageContext, "<tr");
renderRowClassAndId();
ListTagUtil.write(pageContext, ">");
pageContext.setAttribute(rowName, currentObject);
}
else {
return doAfterBodyRenderAfterData();
}
return BodyTagSupport.EVAL_BODY_AGAIN;
}
private void loopTag(TagSupport tag, JSPTreeNodeIF curNode)
throws JspException, IOException {
// loop as long as tag says so
int token;
do {
runTag(tag, curNode);
token = tag.doAfterBody();
} while (token == BodyTagSupport.EVAL_BODY_AGAIN);
if (token != BodyTagSupport.SKIP_BODY)
throw new OntopiaRuntimeException("Internal error: unknown doAfterBody token: " + token);
}
private int doAfterBodyRenderData() throws JspException {
// if there was a previous object, close its row
if (currentObject != null) {
ListTagUtil.write(pageContext, "</tr>");
}
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.RENDER);
if (iterator.hasNext()) {
Object obj = iterator.next();
if (RhnListTagFunctions.isExpandable(obj)) {
parentObject = obj;
}
currentObject = obj;
}
else {
currentObject = null;
}
if (currentObject != null) {
ListTagUtil.write(pageContext, "<tr");
renderRowClassAndId();
ListTagUtil.write(pageContext, ">");
pageContext.setAttribute(rowName, currentObject);
}
else {
return doAfterBodyRenderAfterData();
}
return BodyTagSupport.EVAL_BODY_AGAIN;
}
private int doAfterBodyRenderAfterData() throws JspException {
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.AFTER_RENDER);
ListTagUtil.write(pageContext, "</tbody>");
return BodyTagSupport.EVAL_BODY_AGAIN;
}
/**
* Tests normal conditions for ListTag.
* @throws Exception something bad happened
*/
public void testRegularRun() throws Exception {
context().checking(new Expectations() { {
atLeast(1).of(req).getRequestURI();
will(returnValue("UTF-8"));
atLeast(1).of(req).getAttribute("session");
will(returnValue(webSess));
atLeast(1).of(webSess).getWebUserId();
will(returnValue(null));
atLeast(1).of(req).getParameter(with(containsString("list_")));
will(returnValue(null));
atLeast(1).of(req).setAttribute(
with(equal("pageNum")),
with(any(String.class)));
atLeast(1).of(req).setAttribute(
with(equal("dataSize")),
with(any(String.class)));
atLeast(1).of(pageContext).getOut();
will(returnValue(writer));
atLeast(1).of(pageContext).setAttribute(
with(containsString("_cmd")),
with(any(Object.class)));
atLeast(1).of(pageContext).setAttribute(
with(equal("current")),
with(any(Object.class)));
atLeast(1).of(pageContext).getAttribute("current");
will(returnValue(null));
atLeast(1).of(pageContext).pushBody(with(any(Writer.class)));
atLeast(1).of(pageContext).popBody();
atLeast(1).of(req)
.getParameter(with(containsString("PAGE_SIZE_LABEL_SELECTED")));
will(returnValue(null));
} });
final Action[] cmdValues = {
returnValue(ListCommand.ENUMERATE), // listtag asking
returnValue(ListCommand.ENUMERATE), // columntag asking
returnValue(ListCommand.TBL_HEADING), // listtag asking
returnValue(ListCommand.TBL_HEADING), // columntag asking
returnValue(ListCommand.TBL_ADDONS), // listtag asking
returnValue(ListCommand.TBL_ADDONS), // columntag asking
returnValue(ListCommand.COL_HEADER), // listtag asking
returnValue(ListCommand.COL_HEADER), // columntag asking
returnValue(ListCommand.BEFORE_RENDER), // listtag asking
returnValue(ListCommand.BEFORE_RENDER), // columntag asking
returnValue(ListCommand.RENDER), // listtag asking
returnValue(ListCommand.RENDER), // columntag asking
returnValue(ListCommand.AFTER_RENDER), // listtag asking
returnValue(ListCommand.AFTER_RENDER), // columntag asking
returnValue(ListCommand.TBL_FOOTER), // listtag asking
returnValue(ListCommand.TBL_FOOTER) // columntag asking
};
context().checking(new Expectations() { {
atLeast(1).of(pageContext).getAttribute(with(containsString("_cmd")));
will(onConsecutiveCalls(cmdValues));
} });
int tagval = lt.doStartTag();
assertEquals(BodyTagSupport.EVAL_BODY_INCLUDE, tagval);
do {
tagval = lt.doAfterBody();
} while (tagval == BodyTagSupport.EVAL_BODY_AGAIN);
tagval = lt.doEndTag();
assertEquals(BodyTagSupport.EVAL_PAGE, tagval);
}
private int doAfterBodyRenderAfterData() throws JspException {
ListTagUtil.setCurrentCommand(pageContext, getUniqueName(),
ListCommand.AFTER_RENDER);
ListTagUtil.write(pageContext, "</tbody>");
return BodyTagSupport.EVAL_BODY_AGAIN;
}
/**
* Tests normal conditions for ListTag.
* @throws Exception something bad happened
*/
public void testRegularRun() throws Exception {
context().checking(new Expectations() { {
atLeast(1).of(req).getRequestURI();
will(returnValue("UTF-8"));
atLeast(1).of(req).getAttribute("session");
will(returnValue(webSess));
atLeast(1).of(webSess).getWebUserId();
will(returnValue(null));
atLeast(1).of(req).getParameter(with(containsString("list_")));
will(returnValue(null));
atLeast(1).of(req).setAttribute(
with(equal("pageNum")),
with(any(String.class)));
atLeast(1).of(req).setAttribute(
with(equal("dataSize")),
with(any(String.class)));
atLeast(1).of(pageContext).getOut();
will(returnValue(writer));
atLeast(1).of(pageContext).setAttribute(
with(containsString("_cmd")),
with(any(Object.class)));
atLeast(1).of(pageContext).setAttribute(
with(equal("current")),
with(any(Object.class)));
atLeast(1).of(pageContext).getAttribute("current");
will(returnValue(null));
atLeast(1).of(pageContext).pushBody(with(any(Writer.class)));
atLeast(1).of(pageContext).popBody();
atLeast(1).of(req)
.getParameter(with(containsString("PAGE_SIZE_LABEL_SELECTED")));
will(returnValue(null));
} });
final Action[] cmdValues = {
returnValue(ListCommand.ENUMERATE), // listtag asking
returnValue(ListCommand.ENUMERATE), // columntag asking
returnValue(ListCommand.TBL_HEADING), // listtag asking
returnValue(ListCommand.TBL_HEADING), // columntag asking
returnValue(ListCommand.TBL_ADDONS), // listtag asking
returnValue(ListCommand.TBL_ADDONS), // columntag asking
returnValue(ListCommand.COL_HEADER), // listtag asking
returnValue(ListCommand.COL_HEADER), // columntag asking
returnValue(ListCommand.BEFORE_RENDER), // listtag asking
returnValue(ListCommand.BEFORE_RENDER), // columntag asking
returnValue(ListCommand.RENDER), // listtag asking
returnValue(ListCommand.RENDER), // columntag asking
returnValue(ListCommand.AFTER_RENDER), // listtag asking
returnValue(ListCommand.AFTER_RENDER), // columntag asking
returnValue(ListCommand.TBL_FOOTER), // listtag asking
returnValue(ListCommand.TBL_FOOTER) // columntag asking
};
context().checking(new Expectations() { {
atLeast(1).of(pageContext).getAttribute(with(containsString("_cmd")));
will(onConsecutiveCalls(cmdValues));
} });
int tagval = lt.doStartTag();
assertEquals(BodyTagSupport.EVAL_BODY_INCLUDE, tagval);
do {
tagval = lt.doAfterBody();
} while (tagval == BodyTagSupport.EVAL_BODY_AGAIN);
tagval = lt.doEndTag();
assertEquals(BodyTagSupport.EVAL_PAGE, tagval);
}