use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.
the class WDataTableRenderer method paintRows.
/**
* Paints the rows of the table.
*
* @param table the table to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
private void paintRows(final WDataTable table, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
TableDataModel model = table.getDataModel();
xml.appendTagOpen("ui:tbody");
xml.appendAttribute("id", table.getRepeater().getId());
xml.appendClose();
if (model.getRowCount() == 0) {
xml.appendTag("ui:nodata");
xml.appendEscaped(table.getNoDataMessage());
xml.appendEndTag("ui:nodata");
} else {
// If has at least one visible col, paint the rows.
final int columnCount = table.getColumnCount();
for (int i = 0; i < columnCount; i++) {
if (table.getColumn(i).isVisible()) {
doPaintRows(table, renderContext);
break;
}
}
}
xml.appendEndTag("ui:tbody");
}
use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintWithInvisibleColumnAndNoColumnHeaders.
@Test
public void testDoPaintWithInvisibleColumnAndNoColumnHeaders() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
TableDataModel tableDataModel = createTableModel();
component.setDataModel(tableDataModel);
component.setVisible(true);
final int testColIndex = 1;
final boolean testShowColHeaders = false;
component.getColumn(testColIndex).setVisible(false);
component.setShowColumnHeaders(testShowColHeaders);
// head hidden=true
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/@hidden", component);
// column headers - only COL1 and COL3 showing - in positions 1 and 2 respectively - only 2 cols
assertXpathEvaluatesTo(COL1_HEADING_TEST, "//ui:table/ui:thead/ui:th[1]/ui:decoratedlabel/ui:labelbody", component);
assertXpathEvaluatesTo(COL3_HEADING_TEST, "//ui:table/ui:thead/ui:th[2]/ui:decoratedlabel/ui:labelbody", component);
assertXpathNotExists("//ui:table/ui:thead/ui:th[3]/ui:decoratedlabel/ui:labelbody", component);
// first row - col1 and col3 from model in positions 1 and 2 respectively - only 2 cols showing
String firstName = (String) tableDataModel.getValueAt(0, 0);
String entryDate = (String) tableDataModel.getValueAt(0, 2);
assertXpathEvaluatesTo(firstName, "//ui:table/ui:tbody/ui:tr[1]/ui:td[1]/ui:textfield", component);
assertXpathEvaluatesTo(entryDate, "//ui:table/ui:tbody/ui:tr[1]/ui:td[2]/ui:textfield", component);
assertXpathNotExists("//ui:table/ui:tbody/ui:tr[1]/ui:td[3]/ui:textfield", component);
}
use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintTableActionsInvisibleButton.
@Test
public void testDoPaintTableActionsInvisibleButton() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
TableDataModel tableModel = createTableModel();
component.setDataModel(tableModel);
component.setVisible(true);
WButton button1 = new WButton(TEST_ACTION_ONE);
component.addAction(button1);
// Visible
assertXpathExists("//ui:table/ui:actions", component);
// Not Visible
button1.setVisible(false);
assertXpathNotExists("//ui:table/ui:actions", component);
}
use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintPaginatedServer.
@Test
public void testDoPaintPaginatedServer() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
TableDataModel tableModel = createTableModel();
component.setDataModel(tableModel);
component.setVisible(true);
component.setPaginationMode(PaginationMode.DYNAMIC);
setActiveContext(createUIContext());
assertXpathEvaluatesTo("dynamic", "//ui:table/ui:pagination/@mode", component);
assertXpathEvaluatesTo((new Integer(component.getCurrentPage())).toString(), "//ui:table/ui:pagination/@currentPage", component);
assertXpathEvaluatesTo((new Integer(component.getRowsPerPage())).toString(), "//ui:table/ui:pagination/@rowsPerPage", component);
assertXpathEvaluatesTo((new Integer(tableModel.getRowCount())).toString(), "//ui:table/ui:pagination/@rows", component);
}
use of com.github.bordertech.wcomponents.TableDataModel in project wcomponents by BorderTech.
the class WDataTableRenderer_Test method testDoPaintSortableSortModeServer.
// SERVER outputs "dynamic" see https://github.com/BorderTech/wcomponents/issues/701
@Test
public void testDoPaintSortableSortModeServer() throws IOException, SAXException, XpathException {
WDataTable component = new WDataTable();
component.addColumn(new WTableColumn(COL1_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL2_HEADING_TEST, WTextField.class));
component.addColumn(new WTableColumn(COL3_HEADING_TEST, WTextField.class));
// sortable data model
TableDataModel tableModel = createTableModelSortable();
component.setDataModel(tableModel);
component.setVisible(true);
component.setSortMode(SortMode.SERVER);
assertXpathEvaluatesTo("dynamic", "//ui:table/ui:sort/@mode", component);
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[1]/@sortable", component);
assertXpathNotExists("//ui:table/ui:thead/ui:th[2]/@sortable", component);
assertXpathEvaluatesTo(TRUE, "//ui:table/ui:thead/ui:th[3]/@sortable", component);
}
Aggregations