private void updateTable(BaseEntity current) {
   FacesContext context = FacesContext.getCurrentInstance();
   DataTable dataTable = (DataTable) context.getViewRoot().findComponent("crud:table");
   dataTable.setSelection(current);
   dataTable.processUpdates(context);
   this.setCurrentEntity(current);
 }
Beispiel #2
0
  public void exportPageOnly(DataTable table, Writer writer) throws IOException {
    int first = table.getFirst();
    int rowsToExport = first + table.getRows();

    for (int rowIndex = first; rowIndex < rowsToExport; rowIndex++) {
      exportRow(table, writer, rowIndex);
    }
  }
 /** limpa a ordenação e paginação da data table */
 public void resetDatatable() {
   final DataTable table =
       (DataTable)
           FacesContext.getCurrentInstance().getViewRoot().findComponent(getIdDataTableCrud());
   if (table != null) {
     table.reset();
     table.setSortBy(null);
   }
 }
Beispiel #4
0
  public void exportAll(DataTable table, Writer writer) throws IOException {
    int first = table.getFirst();
    int rowCount = table.getRowCount();
    int rows = table.getRows();
    boolean lazy = table.isLazy();

    if (lazy) {
      for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        if (rowIndex % rows == 0) {
          table.setFirst(rowIndex);
          table.loadLazyData();
        }

        exportRow(table, writer, rowIndex);
      }

      // restore
      table.setFirst(first);
      table.loadLazyData();
    } else {
      for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
        exportRow(table, writer, rowIndex);
      }

      // restore
      table.setFirst(first);
    }
  }
Beispiel #5
0
  protected void exportRow(DataTable table, Writer writer, int rowIndex) throws IOException {
    String var = table.getVar().toLowerCase();
    table.setRowIndex(rowIndex);

    if (!table.isRowAvailable()) {
      return;
    }

    writer.write("\t<" + var + ">\n");
    exportCells(table, writer);
    writer.write("\t</" + var + ">\n");
  }
  public void encode(FacesContext context, DataTableRenderer renderer, DataTable table)
      throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String clientId = table.getClientId(context);
    String[] cellInfo = params.get(clientId + "_cellInfo").split(",");
    int rowIndex = Integer.parseInt(cellInfo[0]);
    int cellIndex = Integer.parseInt(cellInfo[1]);
    int i = -1;
    UIColumn column = null;
    for (UIColumn col : table.getColumns()) {
      if (col.isRendered()) {
        i++;

        if (i == cellIndex) {
          column = col;
          break;
        }
      }
    }

    table.setRowIndex(rowIndex);

    if (column.isDynamic()) {
      DynamicColumn dynamicColumn = (DynamicColumn) column;
      dynamicColumn.applyStatelessModel();
    }

    if (table.isCellEditEscapeRequest(context)) {
      column.getCellEditor().getFacet("input").encodeAll(context);
    } else {
      column.getCellEditor().getFacet("output").encodeAll(context);
    }

    if (column.isDynamic()) {
      ((DynamicColumn) column).cleanStatelessModel();
    }
  }
Beispiel #7
0
  public void exportSelectionOnly(FacesContext context, DataTable table, Writer writer)
      throws IOException {
    Object selection = table.getSelection();
    String var = table.getVar();

    if (selection != null) {
      Map<String, Object> requestMap = context.getExternalContext().getRequestMap();

      if (selection.getClass().isArray()) {
        int size = Array.getLength(selection);

        for (int i = 0; i < size; i++) {
          requestMap.put(var, Array.get(selection, i));

          exportCells(table, writer);
        }
      } else {
        requestMap.put(var, selection);

        exportCells(table, writer);
      }
    }
  }
Beispiel #8
0
  @Override
  public void export(
      FacesContext context,
      DataTable table,
      String filename,
      boolean pageOnly,
      boolean selectionOnly,
      String encodingType,
      MethodExpression preProcessor,
      MethodExpression postProcessor)
      throws IOException {
    ExternalContext externalContext = context.getExternalContext();
    configureResponse(externalContext, filename);
    OutputStream os = externalContext.getResponseOutputStream();
    OutputStreamWriter osw = new OutputStreamWriter(os, encodingType);
    PrintWriter writer = new PrintWriter(osw);

    writer.write("<?xml version=\"1.0\"?>\n");
    writer.write("<" + table.getId() + ">\n");

    if (pageOnly) {
      exportPageOnly(table, writer);
    } else if (selectionOnly) {
      exportSelectionOnly(context, table, writer);
    } else {
      exportAll(table, writer);
    }

    writer.write("</" + table.getId() + ">");

    table.setRowIndex(-1);

    writer.flush();
    writer.close();

    externalContext.responseFlushBuffer();
  }
Beispiel #9
0
  protected void exportCells(DataTable table, Writer writer) throws IOException {
    for (UIColumn col : table.getColumns()) {
      if (!col.isRendered()) {
        continue;
      }

      if (col instanceof DynamicColumn) {
        ((DynamicColumn) col).applyModel();
      }

      if (col.isExportable()) {
        String columnTag = getColumnTag(col);

        addColumnValue(writer, col.getChildren(), columnTag);
      }
    }
  }
 public void seleccionarTramite() {
   tramiteSeleccionado = (TramiteDto) bindingDataTable.getRowData();
   dialogView = true;
 }
Beispiel #11
0
  public void wygeneruj(HashMap lista) throws Exception {
    FacesContext facesCtx = FacesContext.getCurrentInstance();
    ELContext elContext = facesCtx.getELContext();
    ExpressionFactory ef = ExpressionFactory.newInstance();

    akordeon = new AccordionPanel();
    // robienie glownej oprawy
    Set nazwyew = lista.keySet();
    Iterator it;
    it = nazwyew.iterator();
    int i = 0;
    while (it.hasNext()) {
      String nazwapj = (String) it.next();
      Tab tab = new Tab();
      tab.setId("tabek" + i);
      tab.setTitle("ewidencja: " + nazwapj);

      DataTable dataTable = new DataTable();
      dataTable.setId("tablica" + i);
      // dataTable.setResizableColumns(true);
      dataTable.setVar("var");
      dataTable.setValue(lista.get(nazwapj));
      dataTable.setStyle("width: 1000px;");
      // tak trzeba opisac kazda kolumne :)
      ArrayList<String> opisykolumn = new ArrayList<>();
      opisykolumn.addAll(EVatViewPola.getOpispol());
      Iterator itx;
      itx = opisykolumn.iterator();
      while (itx.hasNext()) {
        String wstawka = (String) itx.next();
        Column column = new Column();
        column.setHeaderText(wstawka);
        final String binding = "#{var." + wstawka + "}";
        ValueExpression ve = ef.createValueExpression(elContext, binding, String.class);
        HtmlOutputText ot = new HtmlOutputText();
        ot.setValueExpression("value", ve);
        switch (wstawka) {
          case "kontr":
            column.setWidth("350");
            break;
          case "id":
            column.setWidth("50");
            break;
          case "netto":
            ot.setStyle("float: right;");
            NumberConverter numx = new NumberConverter();
            numx.setMaxFractionDigits(2);
            numx.setMinFractionDigits(2);
            ot.setConverter(numx);
          case "vat":
            ot.setStyle("float: right;");
            NumberConverter numy = new NumberConverter();
            numy.setMaxFractionDigits(2);
            numy.setLocale(new Locale("PL"));
            numy.setGroupingUsed(true);
            ot.setConverter(numy);
        }
        column.getChildren().add(ot);
        dataTable.getChildren().add(column);
      }
      Separator sep = new Separator();
      CommandButton button = new CommandButton();
      button.setValue("PobierzPdf");
      button.setType("button");
      button.setId("przyciskpdf" + i);
      FacesContext context = FacesContext.getCurrentInstance();
      MethodExpression actionListener =
          context
              .getApplication()
              .getExpressionFactory()
              .createMethodExpression(
                  context.getELContext(),
                  "#{pdf.drukujewidencje('zakup')}",
                  null,
                  new Class[] {ActionEvent.class});
      button.addActionListener(new MethodExpressionActionListener(actionListener));
      //            MethodExpression methodExpressionX =
      // context.getApplication().getExpressionFactory().createMethodExpression(
      //            context.getELContext(), "#{pdf.drukujewidencje('"+nazwapj+"')}", null, new
      // Class[] {});
      //            button.setActionExpression(methodExpressionX);
      String nowanazwa;
      if (nazwapj.contains("sprzedaż")) {
        nowanazwa = nazwapj.substring(0, nazwapj.length() - 1);
      } else {
        nowanazwa = nazwapj;
      }
      String tablican =
          "PrimeFaces.ab({source:'form:przyciskpdf"
              + i
              + "',onsuccess:function(data,status,xhr){wydrukewidencje('"
              + wpisView.getPodatnikWpisu()
              + "','"
              + nowanazwa
              + "');;}});return false;";
      button.setOnclick(tablican);
      tab.getChildren().add(dataTable);
      tab.getChildren().add(sep);
      tab.getChildren().add(button);
      akordeon.getChildren().add(tab);

      i++;
    }

    // generowanie podsumowania
    List<EVatwpisSuma> suma2 = new ArrayList<>();
    suma2.addAll(sumaewidencji.values());
    Tab tab = new Tab();
    tab.setId("tabekdsuma");
    tab.setTitle("podsumowanie ewidencji");
    DataTable dataTable = new DataTable();
    dataTable.setId("tablicasuma");
    dataTable.setResizableColumns(true);
    dataTable.setVar("var");
    dataTable.setValue(suma2);
    dataTable.setStyle("width: 1000px;");
    List<String> opisykolumny = new ArrayList<>();
    opisykolumny.add("ewidencja");
    opisykolumny.add("netto");
    opisykolumny.add("vat");
    Iterator ity = opisykolumny.iterator();
    while (ity.hasNext()) {
      String wstawka = (String) ity.next();
      Column column = new Column();
      column.setHeaderText(wstawka);
      HtmlOutputText ot = new HtmlOutputText();
      if (!wstawka.equals("ewidencja")) {
        ot.setStyle("float: right;");
        NumberConverter numberconv = new NumberConverter();
        numberconv.setLocale(new Locale("PL"));
        numberconv.setMinFractionDigits(2);
        numberconv.setMaxFractionDigits(2);
        column.setWidth("200");
        ot.setConverter(numberconv);
      }
      final String binding = "#{var." + wstawka + "}";
      ValueExpression ve = ef.createValueExpression(elContext, binding, String.class);
      ot.setValueExpression("value", ve);
      column.getChildren().add(ot);
      dataTable.getChildren().add(column);
    }
    tab.getChildren().add(dataTable);
    akordeon.getChildren().add(tab);
  }
 public boolean shouldEncode(FacesContext context, DataTable table) {
   return context
       .getExternalContext()
       .getRequestParameterMap()
       .containsKey(table.getClientId(context) + "_cellInfo");
 }