* @throws JspException when the {@link DataGridTagModel} can not be found in the {@link JspContext}
*/
public void doTag()
throws IOException, JspException {
JspContext jspContext = getJspContext();
DataGridTagModel dataGridModel = DataGridUtil.getDataGridTagModel(jspContext);
if(dataGridModel == null)
throw new JspException(Bundle.getErrorString("DataGridTags_MissingDataGridModel"));
if(dataGridModel.getRenderState() == DataGridTagModel.RENDER_STATE_GRID) {
StyleModel styleModel = dataGridModel.getStyleModel();
assert styleModel != null;
TableRenderer tableRenderer = dataGridModel.getTableRenderer();
assert tableRenderer != null;
InternalStringBuilder content = new InternalStringBuilder();
AbstractRenderAppender appender = new StringBuilderRenderAppender(content);
JspFragment fragment = getJspBody();
if(dataGridModel.isRenderRowGroups())
tableRenderer.openTableBody(_tbodyTag, appender);
HttpServletRequest request = JspUtil.getRequest(getJspContext());
while(dataGridModel.hasNextDataItem()) {
StringWriter sw = new StringWriter();
/* first things first -- advance to the next data item */
dataGridModel.nextDataItem();
fragment.invoke(sw);
String trScript = null;
if(_renderRow) {
TrTag.State trState = new TrTag.State();
int index = dataGridModel.getCurrentIndex();
if(index % 2 == 0)
trState.styleClass = styleModel.getRowClass();
else trState.styleClass = styleModel.getAltRowClass();
if(trState.id != null)
trScript = renderNameAndId(request, trState, null);
tableRenderer.openTableRow(trState, appender);
}
content.append(sw.toString());
if(_renderRow) {
tableRenderer.closeTableRow(appender);
if(trScript != null)
appender.append(trScript);
}
}
if(dataGridModel.isRenderRowGroups()) {
tableRenderer.closeTableBody(appender);
String tbodyScript = null;
if(_tbodyTag.id != null) {
tbodyScript = renderNameAndId(request, _tbodyTag, null);
}
if(tbodyScript != null)
appender.append(tbodyScript);
}
jspContext.getOut().write(content.toString());
}
}