protected Class<? extends UIComponent> getComponentClass() {
return AbstractExtendedDataTable.class;
}
public void encodeMetaComponent(FacesContext context, UIComponent component, String metaComponentId) throws IOException {
AbstractExtendedDataTable table = (AbstractExtendedDataTable) component;
if (AbstractExtendedDataTable.SCROLL.equals(metaComponentId)) {
final PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
int clientFirst = table.getClientFirst();
Integer oldClientFirst = (Integer) table.getAttributes().remove(AbstractExtendedDataTable.OLD_CLIENT_FIRST);
if (oldClientFirst == null) {
oldClientFirst = clientFirst;
}
int clientRows = ((SequenceRange) table.getComponentState().getRange()).getRows();
int difference = clientFirst - oldClientFirst;
SequenceRange addRange = null;
SequenceRange removeRange = null;
if (Math.abs(difference) >= clientRows) {
difference = 0;
addRange = new SequenceRange(clientFirst, clientRows);
removeRange = new SequenceRange(oldClientFirst, clientRows);
} else if (difference < 0) {
clientFirst += table.getFirst();
addRange = new SequenceRange(clientFirst, -difference);
removeRange = new SequenceRange(clientFirst + clientRows, -difference);
} else if (difference > 0) {
oldClientFirst += table.getFirst();
removeRange = new SequenceRange(oldClientFirst, difference);
int last = oldClientFirst + clientRows;
addRange = new SequenceRange(last, difference);
}
if (addRange != null) {
Object key = table.getRowKey();
table.captureOrigValue(context);
table.setRowKey(context, null);
final RendererState state = createRowHolder(context, table, null);
state.setCurrentRow(addRange.getFirstRow());
String clientId = table.getClientId(context);
// TODO 1. Encode fixed children
for (state.startIterate(); state.hasNextPart();) {
String partId = state.nextPart().getName().getId();
final List<String> ids = new LinkedList<String>();
table.walk(context, new DataVisitor() {
public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
UIDataTableBase dataTable = state.getRow();
dataTable.setRowKey(context, rowKey);
ids.add(dataTable.getContainerClientId(context) + ":" + state.getPart().getName().getId());
return DataVisitResult.CONTINUE;
}
}, removeRange, null);
table.walk(context, new DataVisitor() {
public DataVisitResult process(FacesContext context, Object rowKey, Object argument) {
UIDataTableBase dataTable = state.getRow();
dataTable.setRowKey(context, rowKey);
HashMap<String, String> attributes = new HashMap<String, String>(1);
String id = dataTable.getContainerClientId(context) + ":" + state.getPart().getName().getId();
attributes.put("id", id);
try {
writer.updateAttributes(ids.remove(0), attributes);
writer.startUpdate(id);
encodeRow(writer, context, state);
writer.endUpdate();
} catch (IOException e) {
throw new FacesException(e);
}
RowHolderBase holder = (RowHolderBase) argument;
holder.nextRow();
return DataVisitResult.CONTINUE;
}
}, addRange, state);
writer.startEval();
if (difference < 0) {
difference += clientRows;
}
// TODO nick - move this to external JavaScript file
writer.write("var richTBody = document.getElementById('" + clientId + ":tb" + partId + "');");
writer.write("var richRows = richTBody.rows;");
writer.write("for (var i = 0; i < " + difference
+ "; i++ ) richTBody.appendChild(richTBody.removeChild(richRows[0]));");
writer.endEval();
}
writer.startUpdate(clientId + ":si");
encodeSelectionInput(writer, context, component);
writer.endUpdate();
writer.startEval();
writer.write("jQuery(" + ScriptUtils.toScript('#' + ScriptUtils.escapeCSSMetachars(clientId))
+ ").triggerHandler('rich:onajaxcomplete', {first: " + table.getClientFirst() + "});");
writer.endEval();
table.setRowKey(context, key);
table.restoreOrigValue(context);
}
} else {
ResponseWriter initialWriter = context.getResponseWriter();
assert !(initialWriter instanceof OnOffResponseWriter);
try {
context.setResponseWriter(new OnOffResponseWriter(initialWriter));
RendererState state = createRowHolder(context, component, null);
state.setEncoderVariance(EncoderVariance.partial);
PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter();
if (UIDataTableBase.HEADER.equals(metaComponentId)) {
encodeHeader(state);
writer.startEval();
writer.write("jQuery("
+ ScriptUtils.toScript('#' + ScriptUtils.escapeCSSMetachars(table.getClientId(context)))
+ ").triggerHandler('rich:onajaxcomplete', {reinitializeHeader: true});");
writer.endEval();
} else if (UIDataTableBase.FOOTER.equals(metaComponentId)) {
encodeFooter(state);
} else if (UIDataTableBase.BODY.equals(metaComponentId)) {
encodeBody(state);
String clientId = table.getClientId(context);
writer.startUpdate(clientId + ":si");
encodeSelectionInput(writer, context, component);
writer.endUpdate();
writer.startEval();
writer.write("jQuery(" + ScriptUtils.toScript('#' + ScriptUtils.escapeCSSMetachars(clientId))
+ ").triggerHandler('rich:onajaxcomplete', {first: " + table.getClientFirst() + ", rowCount: "
+ getRowCount(component) + ", reinitializeBody: true});");
writer.endEval();
} else {
throw new IllegalArgumentException("Unsupported metaComponentIdentifier: " + metaComponentId);
}