Пример #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);
  }
  @Override
  public void onChangePage(
      Container component, int row, int column, int page, TableModel model, EXTable table) {
    LoggedSession s = (LoggedSession) model.getValueAt(column, row, page);

    if (column == 0) {
      component.setText(s.getUsername());
    } else if (column == 1) {
      component.setText(s.getIpAddress());
    } else if (column == 2) {
      component.setText(s.getFullName());
    } else if (column == 3) {
      component.setText(s.getSessionId());
    } else if (column == 4) {
      component.setAttribute("sessionid", s.getSessionId()).addEvent(this, CLICK);
    }
  }
  @Override
  public Container getComponentAt(int row, int column, int page, TableModel model, EXTable table) {

    LoggedSession s = (LoggedSession) model.getValueAt(column, row, page);

    if (column == 0) {
      return new EXContainer("", "label").setText(s.getUsername());
    } else if (column == 1) {
      return new EXContainer("", "label").setText(s.getIpAddress());
    } else if (column == 2) {
      return new EXContainer("", "label").setText(s.getFullName());
    } else if (column == 3) {
      return new EXContainer("", "label").setText(s.getSessionId());
    } else if (column == 4) {
      return new EXIconButton("kill", Icons.ICON_CLOSE)
          .setAttribute("title", "Kill session")
          .setAttribute("sessionid", s.getSessionId())
          .addEvent(this, CLICK);
    } else {
      return null;
    }
  }