- 浏览: 157143 次
- 性别:
- 来自: 上海
文章分类
最新评论
ADF 11g: 表(af: table)分页
转自:http://blog.csdn.net/luyushuang/article/details/6756459
当页面需要显示的数据量比较大的时候,可以使用分页来简化用户的操作。但是在ADF 11g中,af:table并没有默认的分页功能,我们可以custom出JSPX页面的分页逻辑。
本例子使用的表是HR Sechema中的Employees。
2011/11/25 卢玉双 追加:
类似的实现方式,可以使用af:iterator,Table数据取自ADF BC的VO,也能够实现分页功能。
主要使用af:iterator这个tag,页面中数据的展示如同af:table,并且af:iterator可以基于table绑定进行循环显示数据集合。
1,基于Employees表创建entities,然后创建一个stateless session bean,以及data control,代码片段如下:
- publicList<Employees>employeesByLimit(intfirstRow,intmaxRow){
- StringqueryString="select*fromEmployeesorderbyemployee_idASC";
- returnem.createNativeQuery(queryString,
- Employees.class).setMaxResults(maxRow).setFirstResult(firstRow).getResultList();
- }
- /**
- *Returnstotalamountofrowsintable.
- *@returnTotalamountofrowsintable.
- */
- publicintemployeesTotalRows(){
- StringqueryString="select*fromEmployeesorderbyemployee_idASC";
- Queryquery=em.createNativeQuery(queryString);
- Listresults=query.getResultList();
- returnresults.size();
- }
2,在ViewController层创建JSPX页面CustomPagination.jspx
3,创建页面对应的sessionScope级别的managed bean
代码片段:
- privateintfirstRow=0;
- privateintrowsPerPage=10;
- privateinttotalRows;
- privateinttotalPages;
- privateintcurrentPage=1;
- publicCustomPagination(){
- this.loadList();
- }
- publicvoidloadList(){
- /**
- *Returnstotalamountofrowsintable.
- *@returnTotalamountofrowsintable.
- */
- BindingContainerbindings=BindingContext.getCurrent().getCurrentBindingsEntry();
- AttributeBindingattr=(AttributeBinding)bindings.getControlBinding("EmployeesTotalRowCount");
- Stringval=attr.getInputValue().toString();
- introws=Integer.parseInt(val);
- this.setTotalRows(rows);
- doubleval1=((double)this.getTotalRows()/this.getRowsPerPage());
- inttotalPagesCal=(int)Math.ceil(val1);
- this.setTotalPages((totalPagesCal!=0)?totalPagesCal:1);
- }
- publicvoidfirstActionListener(ActionEventactionEvent){
- this.setCurrentPage(1);
- this.setFirstRow(0);
- }
- publicvoidpreviousActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getCurrentPage()-1);
- this.setFirstRow(this.getFirstRow()-this.getRowsPerPage());
- }
- publicvoidnextActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getCurrentPage()+1);
- this.setFirstRow(this.getFirstRow()+this.getRowsPerPage());
- }
- publicvoidlastActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getTotalPages());
- this.setFirstRow(this.getTotalRows()-
- ((this.getTotalRows()%this.getRowsPerPage()!=0)?this.getTotalRows()%
- this.getRowsPerPage():this.getRowsPerPage()));
- }
- publicbooleanisBeforeDisabled(){
- returnthis.getFirstRow()==0;
- }
- publicbooleanisAfterDisabled(){
- returnthis.getFirstRow()>=this.getTotalRows()-this.getRowsPerPage();
- }
- publicvoidsetFirstRow(intfirstRow){
- this.firstRow=firstRow;
- }
- publicintgetFirstRow(){
- returnfirstRow;
- }
- publicvoidsetRowsPerPage(introwsPerPage){
- this.rowsPerPage=rowsPerPage;
- }
- publicintgetRowsPerPage(){
- returnrowsPerPage;
- }
- publicvoidsetTotalRows(inttotalRows){
- this.totalRows=totalRows;
- }
- publicintgetTotalRows(){
- returntotalRows;
- }
- publicvoidsetTotalPages(inttotalPages){
- this.totalPages=totalPages;
- }
- publicintgetTotalPages(){
- returntotalPages;
- }
- publicvoidsetCurrentPage(intcurrentPage){
- this.currentPage=currentPage;
- }
- publicintgetCurrentPage(){
- returncurrentPage;
- }
4,打开CustomPagination页面的数据绑定
1)创建Action绑定
2)在variableIterator标签下添加下面代码
- <variableType="int"Name="employeesTotalRows_Return"IsQueriable="false"IsUpdateable="0"DefaultValue="${bindings.employeesTotalRows.result}"/>
3)创建引用employeesTotalRows_Return的属性绑定
4)创建调用employeesByLimit的Action绑定
5)创建Tree绑定给af:iterator使用
6)创建invokeAction,在页面的prepareMode阶段调用employeesTotalRows Action
7)最终,页面绑定如下图
5,修改页面代码
1)表的Title部分
- <af:panelGroupLayoutid="pgl9"layout="horizontal">
- <af:spacerwidth="10"height="10"id="s9"/>
- <af:panelGroupLayoutid="pgl10"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="EmployeedId"id="ot1"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s7"/>
- <af:panelGroupLayoutid="pgl7"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="FirstName"id="ot6"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s10"/>
- <af:panelGroupLayoutid="pgl11"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="LastName"id="ot4"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s11"/>
- <af:panelGroupLayoutid="pgl12"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="Email"id="ot7"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s12"/>
- <af:panelGroupLayoutid="pgl15"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="Salary"id="ot10"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- </af:panelGroupLayout>
2)表的数据
- <af:iteratorid="i1"value="#{bindings.result.collectionModel}"var="row">
- <af:panelGroupLayoutid="pgl2"layout="horizontal">
- <af:spacerwidth="10"height="10"id="s3"/>
- <af:panelGroupLayoutid="pgl3"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.employeeId}"id="ot8"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s13"/>
- <af:panelGroupLayoutid="pgl13"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.firstName}"id="ot11"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s4"/>
- <af:panelGroupLayoutid="pgl4"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.lastName}"id="ot9"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s6"/>
- <af:panelGroupLayoutid="pgl5"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.email}"id="ot2"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s8"/>
- <af:panelGroupLayoutid="pgl8"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="#{row.salary}"id="ot3"/>
- </af:panelGroupLayout>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s1"/>
- </af:iterator>
3)控制按钮
- <af:panelGroupLayoutid="pgl6">
- <af:commandButtontext="First"id="cb1"
- actionListener="#{CustomPagination.firstActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.beforeDisabled}"/>
- <af:commandButtontext="Prev"id="cb2"
- actionListener="#{CustomPagination.previousActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.beforeDisabled}"/>
- <af:commandButtontext="Next"id="cb3"
- actionListener="#{CustomPagination.nextActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.afterDisabled}"/>
- <af:commandButtontext="Last"id="cb4"
- actionListener="#{CustomPagination.lastActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.afterDisabled}"/>
- </af:panelGroupLayout>
6,运行代码
首页:
第三页:
尾页:
当页面需要显示的数据量比较大的时候,可以使用分页来简化用户的操作。但是在ADF 11g中,af:table并没有默认的分页功能,我们可以custom出JSPX页面的分页逻辑。
本例子使用的表是HR Sechema中的Employees。
2011/11/25 卢玉双 追加:
类似的实现方式,可以使用af:iterator,Table数据取自ADF BC的VO,也能够实现分页功能。
主要使用af:iterator这个tag,页面中数据的展示如同af:table,并且af:iterator可以基于table绑定进行循环显示数据集合。
1,基于Employees表创建entities,然后创建一个stateless session bean,以及data control,代码片段如下:
- publicList<Employees>employeesByLimit(intfirstRow,intmaxRow){
- StringqueryString="select*fromEmployeesorderbyemployee_idASC";
- returnem.createNativeQuery(queryString,
- Employees.class).setMaxResults(maxRow).setFirstResult(firstRow).getResultList();
- }
- /**
- *Returnstotalamountofrowsintable.
- *@returnTotalamountofrowsintable.
- */
- publicintemployeesTotalRows(){
- StringqueryString="select*fromEmployeesorderbyemployee_idASC";
- Queryquery=em.createNativeQuery(queryString);
- Listresults=query.getResultList();
- returnresults.size();
- }
2,在ViewController层创建JSPX页面CustomPagination.jspx
3,创建页面对应的sessionScope级别的managed bean
代码片段:
- privateintfirstRow=0;
- privateintrowsPerPage=10;
- privateinttotalRows;
- privateinttotalPages;
- privateintcurrentPage=1;
- publicCustomPagination(){
- this.loadList();
- }
- publicvoidloadList(){
- /**
- *Returnstotalamountofrowsintable.
- *@returnTotalamountofrowsintable.
- */
- BindingContainerbindings=BindingContext.getCurrent().getCurrentBindingsEntry();
- AttributeBindingattr=(AttributeBinding)bindings.getControlBinding("EmployeesTotalRowCount");
- Stringval=attr.getInputValue().toString();
- introws=Integer.parseInt(val);
- this.setTotalRows(rows);
- doubleval1=((double)this.getTotalRows()/this.getRowsPerPage());
- inttotalPagesCal=(int)Math.ceil(val1);
- this.setTotalPages((totalPagesCal!=0)?totalPagesCal:1);
- }
- publicvoidfirstActionListener(ActionEventactionEvent){
- this.setCurrentPage(1);
- this.setFirstRow(0);
- }
- publicvoidpreviousActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getCurrentPage()-1);
- this.setFirstRow(this.getFirstRow()-this.getRowsPerPage());
- }
- publicvoidnextActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getCurrentPage()+1);
- this.setFirstRow(this.getFirstRow()+this.getRowsPerPage());
- }
- publicvoidlastActionListener(ActionEventactionEvent){
- this.setCurrentPage(this.getTotalPages());
- this.setFirstRow(this.getTotalRows()-
- ((this.getTotalRows()%this.getRowsPerPage()!=0)?this.getTotalRows()%
- this.getRowsPerPage():this.getRowsPerPage()));
- }
- publicbooleanisBeforeDisabled(){
- returnthis.getFirstRow()==0;
- }
- publicbooleanisAfterDisabled(){
- returnthis.getFirstRow()>=this.getTotalRows()-this.getRowsPerPage();
- }
- publicvoidsetFirstRow(intfirstRow){
- this.firstRow=firstRow;
- }
- publicintgetFirstRow(){
- returnfirstRow;
- }
- publicvoidsetRowsPerPage(introwsPerPage){
- this.rowsPerPage=rowsPerPage;
- }
- publicintgetRowsPerPage(){
- returnrowsPerPage;
- }
- publicvoidsetTotalRows(inttotalRows){
- this.totalRows=totalRows;
- }
- publicintgetTotalRows(){
- returntotalRows;
- }
- publicvoidsetTotalPages(inttotalPages){
- this.totalPages=totalPages;
- }
- publicintgetTotalPages(){
- returntotalPages;
- }
- publicvoidsetCurrentPage(intcurrentPage){
- this.currentPage=currentPage;
- }
- publicintgetCurrentPage(){
- returncurrentPage;
- }
4,打开CustomPagination页面的数据绑定
1)创建Action绑定
2)在variableIterator标签下添加下面代码
- <variableType="int"Name="employeesTotalRows_Return"IsQueriable="false"IsUpdateable="0"DefaultValue="${bindings.employeesTotalRows.result}"/>
3)创建引用employeesTotalRows_Return的属性绑定
4)创建调用employeesByLimit的Action绑定
5)创建Tree绑定给af:iterator使用
6)创建invokeAction,在页面的prepareMode阶段调用employeesTotalRows Action
7)最终,页面绑定如下图
5,修改页面代码
1)表的Title部分
- <af:panelGroupLayoutid="pgl9"layout="horizontal">
- <af:spacerwidth="10"height="10"id="s9"/>
- <af:panelGroupLayoutid="pgl10"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="EmployeedId"id="ot1"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s7"/>
- <af:panelGroupLayoutid="pgl7"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="FirstName"id="ot6"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s10"/>
- <af:panelGroupLayoutid="pgl11"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="LastName"id="ot4"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s11"/>
- <af:panelGroupLayoutid="pgl12"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="Email"id="ot7"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s12"/>
- <af:panelGroupLayoutid="pgl15"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="Salary"id="ot10"inlineStyle="font-weight:bold;"/>
- </af:panelGroupLayout>
- </af:panelGroupLayout>
2)表的数据
- <af:iteratorid="i1"value="#{bindings.result.collectionModel}"var="row">
- <af:panelGroupLayoutid="pgl2"layout="horizontal">
- <af:spacerwidth="10"height="10"id="s3"/>
- <af:panelGroupLayoutid="pgl3"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.employeeId}"id="ot8"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s13"/>
- <af:panelGroupLayoutid="pgl13"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.firstName}"id="ot11"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s4"/>
- <af:panelGroupLayoutid="pgl4"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.lastName}"id="ot9"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s6"/>
- <af:panelGroupLayoutid="pgl5"layout="horizontal"inlineStyle="width:75px;">
- <af:outputTextvalue="#{row.email}"id="ot2"/>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s8"/>
- <af:panelGroupLayoutid="pgl8"inlineStyle="width:75px;"layout="horizontal">
- <af:outputTextvalue="#{row.salary}"id="ot3"/>
- </af:panelGroupLayout>
- </af:panelGroupLayout>
- <af:spacerwidth="10"height="10"id="s1"/>
- </af:iterator>
3)控制按钮
- <af:panelGroupLayoutid="pgl6">
- <af:commandButtontext="First"id="cb1"
- actionListener="#{CustomPagination.firstActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.beforeDisabled}"/>
- <af:commandButtontext="Prev"id="cb2"
- actionListener="#{CustomPagination.previousActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.beforeDisabled}"/>
- <af:commandButtontext="Next"id="cb3"
- actionListener="#{CustomPagination.nextActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.afterDisabled}"/>
- <af:commandButtontext="Last"id="cb4"
- actionListener="#{CustomPagination.lastActionListener}"
- partialTriggers="i1"disabled="#{CustomPagination.afterDisabled}"/>
- </af:panelGroupLayout>
6,运行代码
首页:
第三页:
尾页:
相关推荐
ADF中最常用的Table组件af:table具有非常多的内置功能,如排序、过滤、切换列位置,以及通过滚动条来实现的分页。默认情况下,通过滚动条,af:table会和后端的data control配合实现数据分批展现。在af:table中选择某...
ADF实现多选框及分页的Table组件,提供例如上一页,下一页,首页,尾页,以及页码下拉菜单来实现数据分页显示
adf 11g Model层API
Oracle ADF 11g回车键执行Action JS
ADF11G开发规范
ADF开发必读:oracle JDeveloper Application开发框架和开发工具的使用
ORACLE英文版学习资料 JDeveloper和ADF 11g新文档集 oracle-11g-english
ADF 11g:自定义JSF Validator 全文参见 http://blog.csdn.net/ygj26/article/details/8314708
包含weblogic服务器安装与配置,ADF 11g应用部署,有详细截图
ADF样本 ADF样品 管道:01_plCopyOneTextFile 说明:将一个文本/ CSV文件从一个文件夹复制到BLOB中的另一个文件夹组件:复制数据 管道:02_plCopyAllTextFiles 说明:将所有文本/ CSV文件从一个文件夹复制到BLOB中...
adf入门开发相关
Web 2.0 Oracle ADF 应用开发框架 ADF Model 模型 ADF BC 业务组件 ADF View 视图 ADF Controller 控制器
ORACLE_ADF_11g
ORACLE_ADF_11g讲解
Oracle ADF 11g在RichTable添加行到最后一行
Oracle ADF JDeveloper10g应用到11g迁移(中英文对照)
ADF示例的目标该存储库的目标是提供工作源代码作为示例,以及一些有用的组件,这些组件将作为您的用例和自定义应用程序的灵感。 这个想法是使开发人员能够共享一些最佳实践和有用的技巧,以缩短学习曲线并缩短产品...
ADF4351配置程序,主要是C51配置ADF5351/4350
Oracle-ADF-项目 致力于: 测试项目-v3
[Packt Publishing] Oracle ADF 11gR2 初学者开发指南 (英文版) [Packt Publishing] Oracle ADF 11gR2 Development Beginner's Guide (E-Book) ☆ 出版信息:☆ [作者信息] Vinod Krishnan [出版机构] Packt ...