/** * Sets the number of rows to display per page when pagination is enabled. * <p> * If rows per page options have been set, then the value must be a valid option, which can include zero to indicate * show all rows, otherwise the value must be greater than zero. * </p> * * @param rowsPerPage the rowsPerPage to set */ public void setRowsPerPage(final int rowsPerPage) { List<Integer> rowsOptions = getRowsPerPageOptions(); if (rowsOptions == null) { if (rowsPerPage < 1) { throw new IllegalArgumentException( "Rows per page must be greater than 0, but got: " + rowsPerPage); } } else if (!rowsOptions.contains(rowsPerPage)) { throw new IllegalArgumentException( "Rows per page is not a valid rows per page option, got: " + rowsPerPage); } getOrCreateComponentModel().rowsPerPage = rowsPerPage; }
@Test public void testRowsPerPageOptionsClearedAndRowsPerPageZero() { WTable table = new WTable(); table.setTableModel(createModel(new String[100][1])); table.setPaginationMode(PaginationMode.CLIENT); // Change to null table.setRowsPerPageOptions(Arrays.asList(0, 1, 2)); Assert.assertNotNull("Rows per options should not be null", table.getRowsPerPageOptions()); table.setRowsPerPage(0); Assert.assertEquals("Rows per page should be 0", 0, table.getRowsPerPage()); table.setRowsPerPageOptions(null); Assert.assertNull("Rows per options should be null", table.getRowsPerPageOptions()); Assert.assertEquals("Rows per page should be the default after the options are set to null", 10, table.getRowsPerPage()); // Change to empty table.setRowsPerPageOptions(Arrays.asList(0, 1, 2)); Assert.assertNotNull("Rows per options should not be null", table.getRowsPerPageOptions()); table.setRowsPerPage(0); Assert.assertEquals("Rows per page should be 0", 0, table.getRowsPerPage()); table.setRowsPerPageOptions(Collections.EMPTY_LIST); Assert.assertNull("Rows per options should be null", table.getRowsPerPageOptions()); Assert. assertEquals( "Rows per page should be the default after the options are set to empty", 10, table.getRowsPerPage()); }
if (rowsStr != null && getRowsPerPageOptions() != null) { try { int newRows = Integer.parseInt(rowsStr);
if (table.getRowsPerPageOptions() != null) { xml.appendTag("ui:rowsselect"); for (Integer option : table.getRowsPerPageOptions()) { xml.appendTagOpen("ui:option"); xml.appendAttribute("value", option);