Exemple #1
0
  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");
  }
Exemple #2
0
  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");
  }