Пример #1
0
  @Override
  public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    int page = Integer.parseInt(request.getParameter("page")) - 1;
    int rows = Integer.parseInt(request.getParameter("rows"));

    int start = page * rows;
    int end = ((page + 1) * rows);

    int total = model_.getRowCount();

    if (end > total) {
      end = total;
    }
    JMap data = new JMap().put("total", total);
    JArray datas = new JArray();
    int c = 0;
    for (int i = start; i < end; i++) {
      JMap row = new JMap();
      for (int j = 0; j < model_.getColumnCount(); j++) {
        row.put(j + "", model_.getValueAt(j, c, page).toString());
      }
      datas.add(row);
      c++;
    }
    data.put("rows", datas);

    ServletOutputStream out = response.getOutputStream();
    response.setHeader("Content-Type", "application/json");
    out.write(data.getJavascript().getBytes());
    out.flush();
    return null;
  }
Пример #2
0
  @Override
  public void onReady(ClientProxy proxy) {

    super.onReady(proxy);

    JMap map = new JMap();
    int columns = model_.getColumnCount();
    JArray cols = new JArray();
    for (int i = 0; i < columns; i++) {
      Class<?> t = model_.getColumnClass(i);
      JMap colOpt = new JMap();
      colOpt.put("field", i + "").put("title", model_.getColumnNameAt(i));

      if (t.isAssignableFrom(Boolean.class)) {
        colOpt.put("checkbox", true);
      }
      cols.add(new JArray().add(colOpt));
    }

    map.put("columns", cols);
    map.put("url", ResourceUtil.getMethodUrl(this));

    map.put("pagination", true);
    map.put("showFooter", true);

    proxy.addMethod("datagrid", map);
  }