How to calculate ADF table column
2014-08-15 23:22
337 查看
一、概述
很多时候,我们需要统计表格的某一列的总和,然而ADF table并没有直接提供这种功能,这需要我们自己写代码来实现。效果如下图:
二、实现
BC层实现
假设当前表格基于的VO名为SearchRebateVO,里面有入库数量、出库数量、销售金额、现有数量列需要求和,现在只以销售金额(对应VO中的字段为AdjSaleAmount)为例,在VO中新建一个名为(TotalAdjSaleAmount)的字段,为oracle.jbo.domain.Number(与AdjSaleAmount类型一致)。如图所示:
然后生成VO对应的VOImpl和VORowImpl类(SearchRebateVOImpl和SearchRebateVORowImpl),在VOImpl添加一个方法为如下
为了便于代码的重用,对如何汇总做了封装,这里继承了ViewObjectImpl里面对getTotal(StringattributeName)做了实现
将VOImpl类由原来继承ViewObjectImpl,改为继承类CustomViewObjectImpl。接下来,在VORowImpl类中做适当的修改
现在只需要在页面进行些处理就OK了
UI层实现
在页面定义文件中添加AttributeBinding,如下图步骤
在页面table的column footer中通过EL表达式引用TotalAdjSaleAmount
注:如果需要给outputText组件添加convertNumber,outputText的value中不能出现非数字字符,另外还需写成#{bindings.TotalAdjSaleAmount.inputValue},因为#{bindings.TotalAdjSaleAmount}是非数字类型的对象。
并且给该文本输出框添加partialTriggers和rendered(添加rendered,如果表格没有显示行的时候,将不会显示tablefooter)
<f:facet name="footer">
<af:outputTextvalue="汇总:#{bindings.TotalAdjSaleAmount}" id="ot1"
inlineStyle="text-align:right;"
partialTriggers="s4:it3 s5:it8"
rendered="#{bindings.SearchRebate1.estimatedRowCount>
0}"/>
</f:facet>
ae27
很多时候,我们需要统计表格的某一列的总和,然而ADF table并没有直接提供这种功能,这需要我们自己写代码来实现。效果如下图:
二、实现
BC层实现
假设当前表格基于的VO名为SearchRebateVO,里面有入库数量、出库数量、销售金额、现有数量列需要求和,现在只以销售金额(对应VO中的字段为AdjSaleAmount)为例,在VO中新建一个名为(TotalAdjSaleAmount)的字段,为oracle.jbo.domain.Number(与AdjSaleAmount类型一致)。如图所示:
然后生成VO对应的VOImpl和VORowImpl类(SearchRebateVOImpl和SearchRebateVORowImpl),在VOImpl添加一个方法为如下
public Number getTotalAdjSalesAmount() { return getTotal("AdjSaleAmount"); } |
为了便于代码的重用,对如何汇总做了封装,这里继承了ViewObjectImpl里面对getTotal(StringattributeName)做了实现
import oracle.jbo.Row; import oracle.jbo.RowSetIterator; import oracle.jbo.domain.Number; import oracle.jbo.server.ViewObjectImpl; public class CustomViewObjectImpl extends ViewObjectImpl { protected Number getTotal(String attributeName) { Number total = new Number(0); RowSetIterator rsi = createRowSetIterator(null); while (rsi.hasNext()) { Row r = rsi.next(); Number adjSaleAmount = (Number)r.getAttribute(attributeName); if (adjSaleAmount != null) { total = total.add(adjSaleAmount); } } rsi.closeRowSetIterator(); return total; } } |
将VOImpl类由原来继承ViewObjectImpl,改为继承类CustomViewObjectImpl。接下来,在VORowImpl类中做适当的修改
public Number getTotalAdjSaleAmount() { return((SearchRebateVOImpl)getViewObject()).getTotalAdjSalesAmount(); //return (Number) getAttributeInternal(TOTALADJSALEAMOUNT); } |
现在只需要在页面进行些处理就OK了
UI层实现
在页面定义文件中添加AttributeBinding,如下图步骤
在页面table的column footer中通过EL表达式引用TotalAdjSaleAmount
注:如果需要给outputText组件添加convertNumber,outputText的value中不能出现非数字字符,另外还需写成#{bindings.TotalAdjSaleAmount.inputValue},因为#{bindings.TotalAdjSaleAmount}是非数字类型的对象。
并且给该文本输出框添加partialTriggers和rendered(添加rendered,如果表格没有显示行的时候,将不会显示tablefooter)
<f:facet name="footer">
<af:outputTextvalue="汇总:#{bindings.TotalAdjSaleAmount}" id="ot1"
inlineStyle="text-align:right;"
partialTriggers="s4:it3 s5:it8"
rendered="#{bindings.SearchRebate1.estimatedRowCount>
0}"/>
</f:facet>
ae27
相关文章推荐
- How to use listeners on ADF Table Tree TreeTable
- How do I see all foreign keys to a table or column?
- MySQL: How to add column to existing table
- How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition [ID 846405.1]
- Oracle table fragmentation how to calculate or get the actual used blocks of the table
- How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition [ID 846405.1]
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- How To Partition Existing Table Using DBMS_Redefinition
- Mysql官方文档中争对安全添加列的处理方法。Mysql Add a Column to a table if not exists
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- How to import an oracle dump into a different tablespace
- How to calculate the rectangle area of a projected sphere
- How to recover a skipped tablespace after an incomplete recovery with resetlogs? [ID 1561645.1]
- SQL SERVER – 2005 – Database Table Partitioning Tutorial – How to Horizontal Partition Database Table
- how to deal with fdisk error: Re-reading the partition table failed with error 16: Device or resource busy.
- How to Calculate IP/TCP/UDP Checksum–Part 3 Usage Example and Validation
- Beginning MyBatis 3 Part 3 : How to Get Table’s Generated Ids
- How to convert Word table into Excel using OpenXML
- Hawq学习笔记 --- How to access HDFS data via GPDB external table with gphdfs protocol
- How to get the mapping relationship between two columns in a table