protected int validate(FacesContext context, UIComponent source, UIComponent last, String expression) { if (!(last instanceof UIData)) { throw new FacesException("The last resolved component must be instance of UIData to support @row. Expression: \"" + expression + "\" referenced from \"" + last.getClientId(context) + "\"."); } try { Matcher matcher = PATTERN.matcher(expression); if (matcher.matches()) { int row = Integer.parseInt(matcher.group(1)); if (row < 0) { throw new FacesException("Row number must be greater than 0. Expression: \"" + expression + "\""); } UIData data = (UIData) last; if (data.getRowCount() < row + 1) { throw new FacesException("The row count of the target is lesser than the row number. Expression: \"" + expression + "\""); } return row; } else { throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\""); } } catch (Exception e) { throw new FacesException("Expression does not match following pattern @row(n). Expression: \"" + expression + "\"", e); } }
/** * @return int */ public int getRowCount() { return getUIData().getRowCount(); }
/** * <p>Return the value of the <code>rowCount</code> property.</p> */ public int getRowCount() { return getUIData().getRowCount(); }
/** * <p>Return the value of the <code>pageCount</code> property.</p> */ public int getPageCount() { UIData uiData = getUIData(); int rows = uiData.getRows(); int pageCount; if (rows > 0) { pageCount = rows <= 0 ? 1 : uiData.getRowCount() / rows; if (uiData.getRowCount() % rows > 0) { pageCount++; } } else { rows = 1; pageCount = 1; } return pageCount; }
/** * Update the row of the given {@link UIData} component at the given zero-based row index. This will basically * update all direct children of all {@link UIColumn} components at the given row index. * <p> * Note that the to-be-updated direct child of {@link UIColumn} must be a fullworthy JSF UI component which renders * a concrete HTML element to the output, so that JS/ajax can update it. So if you have due to design restrictions * for example a <code><h:panelGroup rendered="..."></code> without an ID, then you should give it an ID. * This way it will render a <code><span id="..."></code> which is updateable by JS/ajax. * @param table The {@link UIData} component. * @param index The zero-based index of the row to be updated. * @since 1.3 */ public static void updateRow(UIData table, int index) { if (index < 0 || table.getRowCount() < 1 || index >= table.getRowCount() || table.getChildCount() == 0) { return; } updateRowCells(table, index); }
/** * Update the row of the given {@link UIData} component at the given zero-based row index. This will basically * update all direct children of all {@link UIColumn} components at the given row index. * <p> * Note that the to-be-updated direct child of {@link UIColumn} must be a fullworthy JSF UI component which renders * a concrete HTML element to the output, so that JS/ajax can update it. So if you have due to design restrictions * for example a <code><h:panelGroup rendered="..."></code> without an ID, then you should give it an ID. * This way it will render a <code><span id="..."></code> which is updateable by JS/ajax. * @param table The {@link UIData} component. * @param index The zero-based index of the row to be updated. * @since 1.3 */ public static void updateRow(UIData table, int index) { if (index < 0 || table.getRowCount() < 1 || index >= table.getRowCount() || table.getChildCount() == 0) { return; } updateRowCells(table, index); }
/** * @return the page count of the uidata */ public int getPageCount() { UIData uiData = getUIData(); int rows = uiData.getRows(); int pageCount; if (rows > 0) { pageCount = rows <= 0 ? 1 : uiData.getRowCount() / rows; if (uiData.getRowCount() % rows > 0) { pageCount++; } } else { rows = 1; pageCount = 1; } return pageCount; }
private static void updateRowCells(UIData columns, Collection<String> renderIds, String tableId, int index, char separator) { String columnId = columns.getId(); int columnCount = columns.getRowCount(); for (UIComponent cell : columns.getChildren()) { for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { renderIds.add(format("%s%c%d%c%s%c%d%c%s", tableId, separator, index, separator, columnId, separator, columnIndex, separator, cell.getId())); } } }
private static void updateRowCells(UIData columns, Collection<String> renderIds, String tableId, int index, char separator) { String columnId = columns.getId(); int columnCount = columns.getRowCount(); for (UIComponent cell : columns.getChildren()) { for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) { renderIds.add(format("%s%c%d%c%s%c%d%c%s", tableId, separator, index, separator, columnId, separator, columnIndex, separator, cell.getId())); } } }
/** * Update the column of the given {@link UIData} component at the given zero-based column index. This will basically * update all direct children of the {@link UIColumn} component at the given column index in all rows. The column * index is the physical column index and does not depend on whether one or more columns is rendered or not (i.e. it * is not necessarily the same column index as the enduser sees in the UI). * <p> * Note that the to-be-updated direct child of {@link UIColumn} must be a fullworthy JSF UI component which renders * a concrete HTML element to the output, so that JS/ajax can update it. So if you have due to design restrictions * for example a <code><h:panelGroup rendered="..."></code> without an ID, then you should give it an ID. * This way it will render a <code><span id="..."></code> which is updateable by JS/ajax. * @param table The {@link UIData} component. * @param index The zero-based index of the column to be updated. * @since 1.3 */ public static void updateColumn(UIData table, int index) { if (index < 0 || table.getRowCount() < 1 || index > table.getChildCount()) { return; } int rowCount = (table.getRows() == 0) ? table.getRowCount() : table.getRows(); if (rowCount == 0) { return; } updateColumnCells(table, index, rowCount); }
/** * Update the column of the given {@link UIData} component at the given zero-based column index. This will basically * update all direct children of the {@link UIColumn} component at the given column index in all rows. The column * index is the physical column index and does not depend on whether one or more columns is rendered or not (i.e. it * is not necessarily the same column index as the enduser sees in the UI). * <p> * Note that the to-be-updated direct child of {@link UIColumn} must be a fullworthy JSF UI component which renders * a concrete HTML element to the output, so that JS/ajax can update it. So if you have due to design restrictions * for example a <code><h:panelGroup rendered="..."></code> without an ID, then you should give it an ID. * This way it will render a <code><span id="..."></code> which is updateable by JS/ajax. * @param table The {@link UIData} component. * @param index The zero-based index of the column to be updated. * @since 1.3 */ public static void updateColumn(UIData table, int index) { if (index < 0 || table.getRowCount() < 1 || index > table.getChildCount()) { return; } int rowCount = (table.getRows() == 0) ? table.getRowCount() : table.getRows(); if (rowCount == 0) { return; } updateColumnCells(table, index, rowCount); }
protected void encodeLastPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId, String namingContainerId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String lastPageLabel = paginator.getLastPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, namingContainerId, "lastPage", lastPageLabel, enabled, false); }
protected void encodeLastPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String lastPageLabel = paginator.getLastPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, "lastPage", lastPageLabel, enabled, false); }
protected void encodeNextPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId, String namingContainerId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String nextPageLabel = paginator.getNextPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, namingContainerId, "nextPage", nextPageLabel, enabled, false); }
protected void encodeNextPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId, String namingContainerId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String nextPageLabel = paginator.getNextPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, namingContainerId, "nextPage", nextPageLabel, enabled, false); }
protected void encodeNextPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String nextPageLabel = paginator.getNextPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, "nextPage", nextPageLabel, enabled, false); }
protected void encodeLastPageListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, UIData uiData, String clientId, String namingContainerId) throws IOException { boolean enabled = ((uiData.getFirst() + uiData.getRows()) < uiData.getRowCount()); String lastPageLabel = paginator.getLastPageLabel(); encodeUnorderedListItem(facesContext, responseWriter, paginator, clientId, namingContainerId, "lastPage", lastPageLabel, enabled, false); }
private void processRows(FacesContext context, int processAction) { UIData parentUIData = getParentUIData(); int first = parentUIData.getFirst(); int rows = parentUIData.getRows(); int last; if (rows == 0) { last = parentUIData.getRowCount(); } else { last = first + rows; } for (int rowIndex = first; rowIndex < last; rowIndex++) { parentUIData.setRowIndex(rowIndex); if (parentUIData.isRowAvailable()) { processColumns(context, processAction); } } }
/** * Sets the dataPaginator to the (n) number of pages forward, defined by the * fastStep property */ public void gotoFastForward() { int fastStep = getFastStep(); if (fastStep <= 0) { fastStep = 1; } int next = getUIData().getFirst() + getUIData().getRows() * fastStep; int rowcount = getUIData().getRowCount(); if (next >= rowcount) { next = (rowcount - 1) - ((rowcount - 1) % getUIData().getRows()); } getUIData().setFirst(next); }
/** * Sets the dataPaginator to the next page */ public void gotoNextPage() { int next = getUIData().getFirst() + getUIData().getRows(); if (isModelResultSet()) { getUIData().setRowIndex(next); if (getUIData().isRowAvailable()) { getUIData().setFirst(next); } } else { if (next < getUIData().getRowCount()) { getUIData().setFirst(next); } } }