Example #1
0
  @Test
  public void render() {

    WebContext webContext = createWebContext();
    CoreContext coreContext = createCoreContext(webContext);

    TableFacade tableFacade = new TableFacade(ID, null);
    tableFacade.setWebContext(webContext);
    tableFacade.setCoreContext(coreContext);

    // create the table
    HtmlTable table = new HtmlTable();
    table.setTheme("jmesa");
    table.setCaption("Presidents");
    table.setWidth("500px");
    table.setStyleClass("table");

    // create the row
    HtmlRow row = new HtmlRow();
    row.setHighlighter(true);
    row.setHighlightClass("highlight");
    table.setRow(row);

    // create some reusable objects

    // create the columns
    HtmlColumn firstNameColumn = new HtmlColumn("name.firstName");
    row.addColumn(firstNameColumn);

    HtmlColumn lastNameColumn = new HtmlColumn("name.lastName");
    row.addColumn(lastNameColumn);

    HtmlColumn termColumn = new HtmlColumn("term");
    row.addColumn(termColumn);

    HtmlColumn careerColumn = new HtmlColumn("career");
    row.addColumn(careerColumn);

    tableFacade.setTable(table);

    // create the view
    SimpleToolbar toolbar = new SimpleToolbar();
    toolbar.setMaxRowsIncrements(new int[] {12, 24, 36});
    toolbar.setTable(table);
    toolbar.setWebContext(webContext);
    toolbar.setCoreContext(coreContext);
    toolbar.setExportTypes(TableModel.CSV);
    HtmlView view = new HtmlView();
    view.setTable(table);
    view.setToolbar(toolbar);
    view.setCoreContext(coreContext);

    Object html = view.render();

    assertNotNull(html);
  }
  private String html(TableFacade tableFacade) {

    // set the column properties
    tableFacade.setColumnProperties(
        "versionName",
        "ruleName",
        "ruleExpression",
        "executeOnPlaceHolder",
        "actionTypePlaceHolder",
        "actionSummaryPlaceHolder",
        "link");

    HtmlTable table = (HtmlTable) tableFacade.getTable();
    table.setCaption("Rules");
    table.getTableRenderer().setWidth("900px");

    HtmlRow row = table.getRow();

    HtmlColumn versionName = row.getColumn("versionName");
    versionName.setTitle("CRF Version");

    HtmlColumn ruleName = row.getColumn("ruleName");
    ruleName.setTitle("Rule Name");

    HtmlColumn career = row.getColumn("ruleExpression");
    career.setWidth("100px");
    career.setTitle("Expression");

    HtmlColumn executeOn = row.getColumn("executeOnPlaceHolder");
    executeOn.setSortable(false);
    executeOn.setFilterable(false);
    executeOn.setTitle("Execute On");
    executeOn
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              @SuppressWarnings("unchecked")
              public Object getValue(Object item, String property, int rowcount) {
                String value = "";
                List<RuleActionBean> ruleActions =
                    (List<RuleActionBean>)
                        new BasicCellEditor().getValue(item, "actions", rowcount);
                for (int i = 0; i < ruleActions.size(); i++) {
                  value += ruleActions.get(i).getExpressionEvaluatesTo();
                  // Do not add horizontal line after last Summary
                  if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                  }
                }
                return value;
              }
            });

    HtmlColumn actionTypePlaceHolder = row.getColumn("actionTypePlaceHolder");
    actionTypePlaceHolder.setSortable(false);
    actionTypePlaceHolder.setFilterable(false);
    actionTypePlaceHolder.setTitle("Action Type");
    actionTypePlaceHolder
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              @SuppressWarnings("unchecked")
              public Object getValue(Object item, String property, int rowcount) {
                String value = "";
                List<RuleActionBean> ruleActions =
                    (List<RuleActionBean>)
                        new BasicCellEditor().getValue(item, "actions", rowcount);
                for (int i = 0; i < ruleActions.size(); i++) {
                  value += ruleActions.get(i).getActionType().name();
                  // Do not add horizontal line after last Summary
                  if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                  }
                }
                return value;
              }
            });

    HtmlColumn actionSummaryPlaceHolder = row.getColumn("actionSummaryPlaceHolder");
    actionSummaryPlaceHolder.setSortable(false);
    actionSummaryPlaceHolder.setFilterable(false);
    actionSummaryPlaceHolder.setTitle("Action Summary");
    actionSummaryPlaceHolder
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              @SuppressWarnings("unchecked")
              public Object getValue(Object item, String property, int rowcount) {
                String value = "";
                List<RuleActionBean> ruleActions =
                    (List<RuleActionBean>)
                        new BasicCellEditor().getValue(item, "actions", rowcount);
                for (int i = 0; i < ruleActions.size(); i++) {
                  value += ruleActions.get(i).getSummary();
                  // Do not add horizontal line after last Summary
                  if (i != ruleActions.size() - 1) {
                    value += "<hr>";
                  }
                }
                return value;
              }
            });

    HtmlColumn link = row.getColumn("link");
    link.setSortable(false);
    link.setFilterable(false);
    link.setTitle("Action");
    link.getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              @SuppressWarnings("unchecked")
              public Object getValue(Object item, String property, int rowcount) {
                String value =
                    (String) new BasicCellEditor().getValue(item, "ruleSetRuleId", rowcount);
                HtmlBuilder html = new HtmlBuilder();
                html.a()
                    .href()
                    .quote()
                    .append(request.getContextPath() + "/someAction?ruleSetRuleId=" + value)
                    .quote()
                    .close();
                html.img().name("bt_View1").src("images/bt_View.gif").border("0").end();
                html.aEnd();
                return html.toString();
              }
            });

    return tableFacade.render(); // Return the Html.
  }
  private String buildTable(TableFacade tableFacade) {
    tableFacade.setColumnProperties("psgName", "OFltNo", "fltDate", "depAirport", "arrAirport");

    HtmlTable table = (HtmlTable) tableFacade.getTable();
    table.getTableRenderer().setWidth("350px");
    HtmlRow row = table.getRow();
    row.setFilterable(Boolean.FALSE);
    MouseRowEvent onmouseout = new MouseRowEvent();
    onmouseout.setStyleClass("odd");
    MouseRowEvent onmouseover = new MouseRowEvent();
    onmouseout.setStyleClass("even");
    row.setOnmouseout(onmouseout);
    // table.setCaption("测试用户信息列表");

    HtmlColumn id = row.getColumn("psgName");
    id.setFilterable(false);
    id.setTitle("旅客");
    id.setSortable(Boolean.FALSE);
    HtmlColumn firstName = row.getColumn("OFltNo");
    firstName.setTitle("航班");

    HtmlColumn deleteAction = row.getColumn("arrAirport");
    deleteAction.setTitle("到达");
    deleteAction.setSortable(Boolean.FALSE);

    deleteAction
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              public Object getValue(Object item, String property, int rowcount) {
                Object value = new BasicCellEditor().getValue(item, property, rowcount);
                HtmlBuilder html = new HtmlBuilder();

                /*
                 * Object id = ItemUtils.getItemValue(item, "airportCode");
                 *
                 * html.a().href().quote().append(request.getContextPath()+
                 * "/setupModify.action?saveKey="+id).quote().close();
                 * html.img()
                 * .src(request.getContextPath()+"/images/pencil.png").
                 * border("none").end(); html.aEnd();
                 */
                if (value != null && value.toString().toUpperCase().equals("CAN")) {
                  html.append(value.toString()).append("(gz)");
                } else html.append(value);
                return html.toString();
              }
            });
    HtmlColumn arrAction = row.getColumn("depAirport");
    arrAction.setTitle("起飞");
    arrAction.setSortable(Boolean.FALSE);

    arrAction
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              public Object getValue(Object item, String property, int rowcount) {
                Object value = new BasicCellEditor().getValue(item, property, rowcount);
                HtmlBuilder html = new HtmlBuilder();

                /*
                 * Object id = ItemUtils.getItemValue(item, "airportCode");
                 *
                 * html.a().href().quote().append(request.getContextPath()+
                 * "/setupModify.action?saveKey="+id).quote().close();
                 * html.img()
                 * .src(request.getContextPath()+"/images/pencil.png").
                 * border("none").end(); html.aEnd();
                 */
                if (value != null && value.toString().toUpperCase().equals("CAN")) {
                  html.append(value.toString()).append("(gz)");
                } else html.append(value);
                return html.toString();
              }
            });
    HtmlColumn fltdateAction = row.getColumn("fltDate");
    fltdateAction.setTitle("起飞日期");
    fltdateAction.setSortable(Boolean.FALSE);

    fltdateAction
        .getCellRenderer()
        .setCellEditor(
            new CellEditor() {
              private Format sm = new SimpleDateFormat("dd/MMM", Locale.ENGLISH);

              public Object getValue(Object item, String property, int rowcount) {
                Object value = new BasicCellEditor().getValue(item, property, rowcount);
                HtmlBuilder html = new HtmlBuilder();
                html.append(sm.format(value));
                return html.toString();
              }
            });
    return tableFacade.render();
  }