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 encodePartially(FacesContext facesContext, UIComponent component) throws IOException { DataGrid grid = (DataGrid) component; ServletResponse response = (ServletResponse) facesContext.getExternalContext().getResponse(); response.setContentType("text/xml"); ResponseWriter writer = facesContext.getResponseWriter(); try { writer.write("<?xml version=\"1.0\" encoding=\"" + response.getCharacterEncoding() + "\"?>"); writer.write("<partial-response>"); // Tab content writer.write("<table>"); RendererUtils.startCDATA(facesContext); encodeTable(facesContext, grid, (grid.isPaginator() && grid.isEffect())); RendererUtils.endCDATA(facesContext); writer.write("</table>"); // State writer.write("<state>"); RendererUtils.startCDATA(facesContext); StateManager stateManager = facesContext.getApplication().getStateManager(); stateManager.writeState(facesContext, stateManager.saveView(facesContext)); RendererUtils.endCDATA(facesContext); writer.write("</state>"); writer.write("</partial-response>"); } catch (IOException exception) { exception.printStackTrace(); } facesContext.responseComplete(); }
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"); }