extremetable应用

 自定义html视图
eXtremeTable使用View接口来生成HTML。你可以使用发行包已经提供的视图,或者你可以插入自己的视图实现。如果要定义自己的视图只需实现View接口,扩展AbstractHtmlView类便可。
一个改变eXtremeTable工具条的实例:(定义两个类)
1.Mytoolbar.java
public class MyToolbar extends TwoColumnTableLayout {
        public MyToolbar(HtmlBuilder html, TableModel model) {
               super(html, model);
           }
           protected boolean showLayout(TableModel model) {
               boolean showPagination = BuilderUtils.showPagination(model);
               boolean showExports = BuilderUtils.showExports(model);
               boolean showTitle = BuilderUtils.showTitle(model);
               if (!showPagination && !showExports && !showTitle) {
                   return false;
               }
               return true;
           }
          protected void columnLeft(HtmlBuilder html, TableModel model) {
               html.td(2).close();
               new TableBuilder(html, model).title();
               html.tdEnd();
           }
           protected void columnRight(HtmlBuilder html, TableModel model) {
               boolean showPagination = BuilderUtils.showPagination(model);
               boolean showExports = BuilderUtils.showExports(model);
               ToolbarBuilder toolbarBuilder = new ToolbarBuilder(html, model);
               html.td(2).align("right").close();
                             html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(BuilderConstants.TOOLBAR_CSS).close();
               html.tr(3).close();
               if (showPagination) {
                   html.td(4).close();
                   toolbarBuilder.firstPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.prevPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.nextPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.lastPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.separator();
                   html.tdEnd();
                   html.td(4).close();
             // 在工具条里面添加一个文本框以便手动的控制页面显示的行数
                   /* StringBuffer action = new StringBuffer("javascript:");
                   TableActions ta = new TableActions(model);
                   int currentRowsDisplayed = model.getLimit().getCurrentRowsDisplayed()
                         html.input("text").name(model.getTableHandler().prefixWithTableId() + TableConstants.ROWS_DISPLAYED).value(String.valueOf(currentRowsDisplayed);
                   action.append(ta.getClearedExportTableIdParameters());
                   String form = BuilderUtils.getForm(model);
                   action.append("document.forms.").append(form).append(".");
                               action.append(model.getTableHandler().prefixWithTableId()).append(TableConstants.CURRENT_ROWS_DISPLAYED);
                   action.append(".value=").append("this.value").append(";");
                   action.append(ta.getFormParameter(TableConstants.PAGE, "1"));
                   action.append("if(event.keyCode==13){");
                   action.append(ta.getOnInvokeAction());
                   action.append("}");
                   html.onkeypress(action.toString());
                   html.xclose();
                   html.tdEnd();*/
                  
                   html.td(4).style("width:10px").close();
                   html.newline();
                   html.tabs(4);
                   toolbarBuilder.rowsDisplayedDroplist();
                   html.img();
 html.src(BuilderUtils.getImage(model, BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));
                  html.style("border:0");
                   html.alt("Rows Displayed");
                   html.xclose();
                   html.tdEnd();
                   if (showExports) {
                       html.td(4).close();
                       toolbarBuilder.separator();
                       html.tdEnd();
                   }
               }
               if (showExports) {
                   Iterator iterator = model.getExportHandler().getExports().iterator();
                   for (Iterator iter = iterator; iter.hasNext();) {
                       html.td(4).close();
                       Export export = (Export) iter.next();
                       toolbarBuilder.exportItemAsImage(export);
                       html.tdEnd();
                   }
               }
               html.trEnd(3);
               html.tableEnd(2);
               html.newline();
               html.tabs(2);
               html.tdEnd();
           }
}
2.MyView.java
public class MyView extends AbstractHtmlView {
        protected void beforeBodyInternal(TableModel model) {
               getTableBuilder().tableStart();
               getTableBuilder().theadStart();
               getTableBuilder().filterRow();
               getTableBuilder().headerRow();
               getTableBuilder().theadEnd();
               getTableBuilder().tbodyStart();
           }
           protected void afterBodyInternal(TableModel model) {
               getCalcBuilder().defaultCalcLayout();
               getTableBuilder().tbodyEnd();
               getTableBuilder().tableEnd();
               toolbar(getHtmlBuilder(), getTableModel());
               statusBar(getHtmlBuilder(), get自定义html视图
eXtremeTable使用View接口来生成HTML。你可以使用发行包已经提供的视图,或者你可以插入自己的视图实现。如果要定义自己的视图只需实现View接口,扩展AbstractHtmlView类便可。
一个改变eXtremeTable工具条的实例:(定义两个类)
1.Mytoolbar.java
public class MyToolbar extends TwoColumnTableLayout {
        public MyToolbar(HtmlBuilder html, TableModel model) {
               super(html, model);
           }
           protected boolean showLayout(TableModel model) {
               boolean showPagination = BuilderUtils.showPagination(model);
               boolean showExports = BuilderUtils.showExports(model);
               boolean showTitle = BuilderUtils.showTitle(model);
               if (!showPagination && !showExports && !showTitle) {
                   return false;
               }
               return true;
           }
          protected void columnLeft(HtmlBuilder html, TableModel model) {
               html.td(2).close();
               new TableBuilder(html, model).title();
               html.tdEnd();
           }
           protected void columnRight(HtmlBuilder html, TableModel model) {
               boolean showPagination = BuilderUtils.showPagination(model);
               boolean showExports = BuilderUtils.showExports(model);
               ToolbarBuilder toolbarBuilder = new ToolbarBuilder(html, model);
               html.td(2).align("right").close();
                             html.table(2).border("0").cellPadding("0").cellSpacing("1").styleClass(BuilderConstants.TOOLBAR_CSS).close();
               html.tr(3).close();
               if (showPagination) {
                   html.td(4).close();
                   toolbarBuilder.firstPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.prevPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.nextPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.lastPageItemAsImage();
                   html.tdEnd();
                   html.td(4).close();
                   toolbarBuilder.separator();
                   html.tdEnd();
                   html.td(4).close();
             // 在工具条里面添加一个文本框以便手动的控制页面显示的行数
                   /* StringBuffer action = new StringBuffer("javascript:");
                   TableActions ta = new TableActions(model);
                   int currentRowsDisplayed = model.getLimit().getCurrentRowsDisplayed()
                         html.input("text").name(model.getTableHandler().prefixWithTableId() + TableConstants.ROWS_DISPLAYED).value(String.valueOf(currentRowsDisplayed);
                   action.append(ta.getClearedExportTableIdParameters());
                   String form = BuilderUtils.getForm(model);
                   action.append("document.forms.").append(form).append(".");
                               action.append(model.getTableHandler().prefixWithTableId()).append(TableConstants.CURRENT_ROWS_DISPLAYED);
                   action.append(".value=").append("this.value").append(";");
                   action.append(ta.getFormParameter(TableConstants.PAGE, "1"));
                   action.append("if(event.keyCode==13){");
                   action.append(ta.getOnInvokeAction());
                   action.append("}");
                   html.onkeypress(action.toString());
                   html.xclose();
                   html.tdEnd();*/
                  
                   html.td(4).style("width:10px").close();
                   html.newline();
                   html.tabs(4);
                   toolbarBuilder.rowsDisplayedDroplist();
                   html.img();
 html.src(BuilderUtils.getImage(model, BuilderConstants.TOOLBAR_ROWS_DISPLAYED_IMAGE));
                  html.style("border:0");
                   html.alt("Rows Displayed");
                   html.xclose();
                   html.tdEnd();
                   if (showExports) {
                       html.td(4).close();
                       toolbarBuilder.separator();
                       html.tdEnd();
                   }
               }
               if (showExports) {
                   Iterator iterator = model.getExportHandler().getExports().iterator();
                   for (Iterator iter = iterator; iter.hasNext();) {
                       html.td(4).close();
                       Export export = (Export) iter.next();
                       toolbarBuilder.exportItemAsImage(export);
                       html.tdEnd();
                   }
               }
               html.trEnd(3);
               html.tableEnd(2);
               html.newline();
               html.tabs(2);
               html.tdEnd();
           }
}
2.MyView.java
public class MyView extends AbstractHtmlView {
        protected void beforeBodyInternal(TableModel model) {
               getTableBuilder().tableStart();
               getTableBuilder().theadStart();
               getTableBuilder().filterRow();
               getTableBuilder().headerRow();
               getTableBuilder().theadEnd();
               getTableBuilder().tbodyStart();
           }
           protected void afterBodyInternal(TableModel model) {
               getCalcBuilder().defaultCalcLayout();
               getTableBuilder().tbodyEnd();
               getTableBuilder().tableEnd();
               toolbar(getHtmlBuilder(), getTableModel());
               statusBar(getHtmlBuilder(), getTableModel());
           }
           protected void toolbar(HtmlBuilder html, TableModel model) {
               new MyToolbar(html, model).layout();
           }
           protected void statusBar(HtmlBuilder html, TableModel model) {
               new DefaultStatusBar(html, model).layout();
           }
}
然后在<ec:table>中添加一个属性view=”MyView的完整类名”,运行效果如下:
TableModel());
           }
           protected void toolbar(HtmlBuilder html, TableModel model) {
               new MyToolbar(html, model).layout();
           }
           protected void statusBar(HtmlBuilder html, TableModel model) {
               new DefaultStatusBar(html, model).layout();
           }
}
然后在<ec:table>中添加一个属性view=”MyView的完整类名”。
为表格添加操作
在实际应用,特别是在一些管理系统中前台页面往往查看信息与编辑、删除都放在一起。对于eXtremeTable达到这样的效果只需在jsp文件中(自定义一列)如下:
<ec:column alias="操作 " filterable="false" sortable="false" >
<a href="${pageContext.request.contextPath}/servlet/EmployeeServlet?param=edit&id=${employee.id}">编辑 </a>
<!--使用图片的好处就是可以避免国际化的问题 -->
<a onclick="confirm('真的删除 ');" ><img border="0" src ="${pageContext.request.contextPath}/images/delete.jpg"></a>
</ec:column>


欢迎大家访问我的个人网站 萌萌的IT人

你可能感兴趣的:(extremetable应用)