// prepare to render the tree
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
InternalStringBuilder sb = new InternalStringBuilder(1024);
StringBuilderRenderAppender writer = new StringBuilderRenderAppender(sb);
// this is the treeId from the request. If there was an tree expansion this will be
// non-null and it identifies what tree had the expansion request.
// we need to qualify the tree based upon the tagId
assert(_trs.tagId != null);
_trs.tagId = getIdForTagId(_trs.tagId);
String treeId = request.getParameter(TreeElement.TREE_ID);
if (treeId != null && _trs.tagId.equals(treeId)) {
TreeHelpers.processTreeRequest(treeId, treeRoot, request, response);
}
// check for the nodes that are expanded...
// Add the script support for the tree.
if (_trs.runAtClient) {
IScriptReporter sr = getScriptReporter();
if (sr == null) {
String s = Bundle.getString("Tags_TreeRunAtClientSC", null);
registerTagError(s, null);
reportErrors();
return;
}
ScriptRequestState srs = ScriptRequestState.getScriptRequestState(request);
if (!srs.isFeatureWritten(CoreScriptFeature.DYNAMIC_INIT)) {
String s = Bundle.getString("Tags_TreeHtmlRunAtClient", null);
registerTagError(s, null);
reportErrors();
return;
}
assert(treeRoot instanceof ITreeRootElement);
ITreeRootElement tre = (ITreeRootElement) treeRoot;
Object[] args = new Object[8];
args[0] = _iState.getImageRoot() + "/";
args[1] = tre.getObjectName();
args[2] = _iState.getNodeCollapsedImage();
args[3] = _iState.getNodeExpandedImage();
args[4] = _iState.getLastNodeCollapsedImage();
args[5] = _iState.getLastNodeExpandedImage();
args[6] = Bundle.getString("Tags_TreeAltTextExpand", null);
args[7] = Bundle.getString("Tags_TreeAltTextCollapse", null);
srs.writeFeature(sr, writer, CoreScriptFeature.TREE_INIT, false, false, args);
tre.setTreeRenderState(_trs);
tre.setInheritableState(_iState);
}
// create a containing tree level <div> and place the tree level styles on it.
_divState.styleClass = _treeStyleClass;
_divState.style = _treeStyle;
String divId = null;
if (_renderTagIdLookup) {
_divState.id = _trs.tagId;
divId = _divState.id;
}
// if we are running on the client then we need to output the tree name into the top level tree <div> tag
if (_trs.runAtClient) {
_divState.registerAttribute(AbstractHtmlState.ATTR_GENERAL, "netui:treeName",
((INameable) treeRoot).getObjectName());
}
TagRenderingBase divRenderer = TagRenderingBase.Factory.getRendering(TagRenderingBase.DIV_TAG, request);
divRenderer.doStartTag(writer, _divState);
sb.append("\n");
// Render the tree.
AttributeRenderer extraAttrs = new AttributeRenderer();
TagTreeRenderer ttr = new TagTreeRenderer(this, _trs, request, response, pageContext.getServletContext());
ttr.render(sb, treeRoot, 0, extraAttrs, _iState);
if (hasErrors()) {
reportErrors();
return;
}
// finish the tree representation and write it
divRenderer.doEndTag(writer);
sb.append("\n");
write(sb.toString());
if (!(treeRoot instanceof ITreeRootElement)) {
boolean error = false;
if (_rootNodeExpandedImage != null) {
String s = Bundle.getString("Tags_TreeRootImageError", null);