protected void encodeMarkup(FacesContext facesContext, DataGrid grid) throws IOException { ResponseWriter writer = facesContext.getResponseWriter(); String clientId = grid.getClientId(facesContext); boolean hasPaginator = grid.isPaginator(); String paginatorPosition = grid.getPaginatorPosition(); String styleClass = grid.getStyleClass() == null ? DataGrid.CONTAINER_CLASS : DataGrid.CONTAINER_CLASS + " " + grid.getStyleClass(); writer.startElement("div", grid); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", styleClass, "styleClass"); if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom")) { encodePaginatorContainer(facesContext, clientId + "_paginatorTop"); } encodeTable(facesContext, grid, false); if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top")) { encodePaginatorContainer(facesContext, clientId + "_paginatorBottom"); } writer.endElement("div"); }
public void decode(FacesContext facesContext, UIComponent component) { Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap(); DataGrid grid = (DataGrid) component; String clientId = grid.getClientId(facesContext); boolean isAjaxPaging = params.containsKey(clientId + "_ajaxPaging"); if (isAjaxPaging) { grid.setFirst(Integer.valueOf(params.get(clientId + "_first"))); grid.setRows(Integer.valueOf(params.get(clientId + "_rows"))); grid.setPage(Integer.valueOf(params.get(clientId + "_page"))); } }
protected void encodeTable(FacesContext facesContext, DataGrid grid, boolean hidden) throws IOException { ResponseWriter writer = facesContext.getResponseWriter(); String clientId = grid.getClientId(facesContext); int columns = grid.getColumns(); int rowIndex = grid.getFirst(); int numberOfRowsToRender = (grid.getRows() != 0 ? grid.getRows() : grid.getRowCount()) / columns; writer.startElement("table", grid); writer.writeAttribute("id", clientId + "_table", "id"); writer.writeAttribute("class", DataGrid.TABLE_CLASS, null); if (hidden) writer.writeAttribute("style", "display:none", null); writer.startElement("tbody", null); for (int i = 0; i < numberOfRowsToRender; i++) { writer.startElement("tr", null); writer.writeAttribute("class", DataGrid.TABLE_ROW_CLASS, null); for (int j = 0; j < columns; j++) { grid.setRowIndex(rowIndex); writer.startElement("td", null); writer.writeAttribute("class", DataGrid.TABLE_COLUMN_CLASS, null); if (grid.isRowAvailable()) { renderChildren(facesContext, grid); rowIndex++; } writer.endElement("td"); } writer.endElement("tr"); if (!grid.isRowAvailable()) break; } grid.setRowIndex(-1); // cleanup writer.endElement("tbody"); writer.endElement("table"); }
protected void encodeScript(FacesContext facesContext, DataGrid grid) throws IOException { ResponseWriter writer = facesContext.getResponseWriter(); String clientId = grid.getClientId(facesContext); String widgetVar = createUniqueWidgetVar(facesContext, grid); UIComponent form = ComponentUtils.findParentForm(facesContext, grid); if (form == null) { throw new FacesException("DataGrid : \"" + clientId + "\" must be inside a form element"); } writer.startElement("script", null); writer.writeAttribute("type", "text/javascript", null); writer.write(widgetVar + " = new PrimeFaces.widget.DataGrid('" + clientId + "',{"); writer.write("url:'" + getActionURL(facesContext) + "'"); writer.write(",formId:'" + form.getClientId(facesContext) + "'"); if (grid.isPaginator()) { writer.write(",paginator:new YAHOO.widget.Paginator({"); writer.write("rowsPerPage:" + grid.getRows()); writer.write(",totalRecords:" + grid.getRowCount()); writer.write(",initialPage:" + grid.getPage()); if (grid.getPageLinks() != 10) writer.write(",pageLinks:" + grid.getPageLinks()); if (grid.getPaginatorTemplate() != null) writer.write(",template:'" + grid.getPaginatorTemplate() + "'"); if (grid.getRowsPerPageTemplate() != null) writer.write(",rowsPerPageOptions : [" + grid.getRowsPerPageTemplate() + "]"); if (grid.getFirstPageLinkLabel() != null) writer.write(",firstPageLinkLabel:'" + grid.getFirstPageLinkLabel() + "'"); if (grid.getPreviousPageLinkLabel() != null) writer.write(",previousPageLinkLabel:'" + grid.getPreviousPageLinkLabel() + "'"); if (grid.getNextPageLinkLabel() != null) writer.write(",nextPageLinkLabel:'" + grid.getNextPageLinkLabel() + "'"); if (grid.getLastPageLinkLabel() != null) writer.write(",lastPageLinkLabel:'" + grid.getLastPageLinkLabel() + "'"); if (grid.getCurrentPageReportTemplate() != null) writer.write(",pageReportTemplate:'" + grid.getCurrentPageReportTemplate() + "'"); if (!grid.isPaginatorAlwaysVisible()) writer.write(",alwaysVisible:false"); String paginatorPosition = grid.getPaginatorPosition(); String paginatorContainer = null; if (paginatorPosition.equals("both")) paginatorContainer = clientId + "_paginatorTop','" + clientId + "_paginatorBottom"; else if (paginatorPosition.equals("top")) paginatorContainer = clientId + "_paginatorTop"; else if (paginatorPosition.equals("bottom")) paginatorContainer = clientId + "_paginatorBottom"; writer.write(",containers:['" + paginatorContainer + "']"); writer.write("})"); if (grid.isEffect()) { writer.write(",effect:true"); writer.write(",effectSpeed:'" + grid.getEffectSpeed() + "'"); } } writer.write("});"); writer.endElement("script"); }