1.如果你要做成固定的汇总行(自动汇总当前显示记录,不需要添加任何代码),可以使用普通的 “Table ”(当然也可以使用“AdvanceTable”,不过没必要,“AdvanceTable”创建比较麻烦)。设置方法就是把汇总的字段(汇总字段必须是Number类型)中的属性“Visual -> Total Value”改成“True”即可。
2.如果你要做成动态的汇总行,那你必须用到“AdvanceTable”。具体方法如下:
(1) 创建一个“AdvanceTable”,把相应的字段添加完毕。
a是字段列。
b是字段值。
c是字段显示名称。
(2) 确定要汇总的字段并设置相应属性。
注:选择(1)中描述的“a”可以看到上述属性。
a选择“True”表示改字段是汇总字段。
b是选择当前字段是以什么类型显示,有四种显示类型“iconButtonFormat”、“numberFormat”、“objectNameFormat”、“textFormat”请根据具体情况设定。
(3) 为“AdvanceTable”创建一个“footer”->“total”
(4) 实现全选和全部不选的功能。
i.在 “AdvanceTable”所用的“View Instance”中添加一个字段“Selected_Flag”,如下:
SELECT 'N' as selected_flag
,vendor_line_id
,header_id
,currency_code
,amount
FROM cux_po_cnt_vendors_all
order by vendor_line_id
ii.在“AdvanceTable”中添加一列“SelectedFlagCol”,“View Attribute”选择刚才创建的“SelectedFlag”,然后为其添加“Client Action” (添加此 Ation 是为了在点击的时候能刷新汇总行数值)
iii.为“AdvanceTable”添加一个“tableAtions”,此时修改自动创建的“flowLayout”为“rowLayout”(添加这个是为了显示“全选”和“全部不选”)。然后在“rowLayout”下创建两个“link”,填写“Visual -> Text”为“全选|”和“全部不选”。并且分别添加“Client Action” 为“SelectAll”和“NotSelectAll”,“Action Type”都选择“fireAction”.
iii.添加控制代码
在页面“AMImpl”中写如下代码:
public String[] totalLine() {
String[] str = new String[2];
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
BigDecimal totalAmt = new BigDecimal(0);
double totalId = 0;
RowSetIterator totalIter = vo.createRowSetIterator("totalIter");
// validate record line
if (fetchCount > 0) {
totalIter.setRangeStart(0);
totalIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row = (CuxTestVORowImpl)totalIter.next();
if (row.getSelectedFlag() != null) {
String selectFlag = row.getSelectedFlag();
if (selectFlag.equals("Y")) {
if (row.getAmount() != null) {
System.out.println(String.valueOf(String.valueOf(row.getAmount())));
System.out.println(String.valueOf(String.valueOf(new Number(row.getAmount()))));
totalAmt =
totalAmt.add(new BigDecimal(String.valueOf(row.getAmount())));
//add(totalAmt, Double.valueOf(String.valueOf(row.getAmount())));
System.out.println(String.valueOf(totalAmt));
}
if (row.getHeaderId() != null)
totalId =
totalId + Double.valueOf(row.getHeaderId().toString());
}
}
}
}
totalIter.closeRowSetIterator();
//BigDecimal b1 = new BigDecimal(totalAmt);
DecimalFormat df = new DecimalFormat("#,##0.00");
str[0] = String.valueOf(df.format(totalAmt));
//str[0] = String.valueOf(totalAmt);
str[1] = String.valueOf(totalId);
return str;
}
public void selectAll() {
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
RowSetIterator selectAllIter =
vo.createRowSetIterator("selectAllIter");
// validate record line
if (fetchCount > 0) {
selectAllIter.setRangeStart(0);
selectAllIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row = (CuxTestVORowImpl)selectAllIter.next();
row.setSelectedFlag("Y");
}
}
selectAllIter.closeRowSetIterator();
}
public void notSelectAll() {
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
RowSetIterator notSelectAllIter =
vo.createRowSetIterator("notSelectAllIter");
// validate record line
if (fetchCount > 0) {
notSelectAllIter.setRangeStart(0);
notSelectAllIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row =
(CuxTestVORowImpl)notSelectAllIter.next();
row.setSelectedFlag("N");
}
}
notSelectAllIter.closeRowSetIterator();
}
String[] str = new String[2];
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
BigDecimal totalAmt = new BigDecimal(0);
double totalId = 0;
RowSetIterator totalIter = vo.createRowSetIterator("totalIter");
// validate record line
if (fetchCount > 0) {
totalIter.setRangeStart(0);
totalIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row = (CuxTestVORowImpl)totalIter.next();
if (row.getSelectedFlag() != null) {
String selectFlag = row.getSelectedFlag();
if (selectFlag.equals("Y")) {
if (row.getAmount() != null) {
System.out.println(String.valueOf(String.valueOf(row.getAmount())));
System.out.println(String.valueOf(String.valueOf(new Number(row.getAmount()))));
totalAmt =
totalAmt.add(new BigDecimal(String.valueOf(row.getAmount())));
//add(totalAmt, Double.valueOf(String.valueOf(row.getAmount())));
System.out.println(String.valueOf(totalAmt));
}
if (row.getHeaderId() != null)
totalId =
totalId + Double.valueOf(row.getHeaderId().toString());
}
}
}
}
totalIter.closeRowSetIterator();
//BigDecimal b1 = new BigDecimal(totalAmt);
DecimalFormat df = new DecimalFormat("#,##0.00");
str[0] = String.valueOf(df.format(totalAmt));
//str[0] = String.valueOf(totalAmt);
str[1] = String.valueOf(totalId);
return str;
}
public void selectAll() {
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
RowSetIterator selectAllIter =
vo.createRowSetIterator("selectAllIter");
// validate record line
if (fetchCount > 0) {
selectAllIter.setRangeStart(0);
selectAllIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row = (CuxTestVORowImpl)selectAllIter.next();
row.setSelectedFlag("Y");
}
}
selectAllIter.closeRowSetIterator();
}
public void notSelectAll() {
CuxTestVOImpl vo = getCuxTestVO1();
int fetchCount = vo.getRowCount();
RowSetIterator notSelectAllIter =
vo.createRowSetIterator("notSelectAllIter");
// validate record line
if (fetchCount > 0) {
notSelectAllIter.setRangeStart(0);
notSelectAllIter.setRangeSize(fetchCount);
for (int i = 0; i < fetchCount; i++) {
CuxTestVORowImpl row =
(CuxTestVORowImpl)notSelectAllIter.next();
row.setSelectedFlag("N");
}
}
notSelectAllIter.closeRowSetIterator();
}
在页面“CO”控制中添加一个函数
/**
* 设置界面汇总字段值
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void setTotalFieldValue(OAPageContext pageContext,
OAWebBean webBean){
OAApplicationModule am = pageContext.getApplicationModule(webBean);
String[] str = new String[1];
* 设置界面汇总字段值
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void setTotalFieldValue(OAPageContext pageContext,
OAWebBean webBean){
OAApplicationModule am = pageContext.getApplicationModule(webBean);
String[] str = new String[1];
/* 获取汇总字段值 */
str = (String[])am.invokeMethod("totalLine");
str = (String[])am.invokeMethod("totalLine");
/* 获得页面Bean */
OAAdvancedTableBean advtableBean =
(OAAdvancedTableBean)webBean.findIndexedChildRecursive("region4");
OAMessageTextInputBean amountBean =
(OAMessageTextInputBean)advtableBean.findChildRecursive("Amount");
// compute the total
amountBean.setAttributeValue(TABULAR_FUNCTION_VALUE_ATTR, str[0]);
}
OAAdvancedTableBean advtableBean =
(OAAdvancedTableBean)webBean.findIndexedChildRecursive("region4");
OAMessageTextInputBean amountBean =
(OAMessageTextInputBean)advtableBean.findChildRecursive("Amount");
// compute the total
amountBean.setAttributeValue(TABULAR_FUNCTION_VALUE_ATTR, str[0]);
}
分别在 processRequest 和 processFormRequest 中写入如下代码
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject vo = (OAViewObject)am.findViewObject("CuxTestVO1");
if (vo != null) {
vo.setWhereClause(null);
vo.setWhereClauseParams(null);
//执行查询
vo.executeQuery();
}
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean) {
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
OAViewObject vo = (OAViewObject)am.findViewObject("CuxTestVO1");
if (vo != null) {
vo.setWhereClause(null);
vo.setWhereClauseParams(null);
//执行查询
vo.executeQuery();
}
/* 设置界面汇总字段值 */
setTotalFieldValue(pageContext, webBean);
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext,
OAWebBean webBean) {
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if (pageContext.getParameter(EVENT_PARAM).equals("SelectAll")) {
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext,
OAWebBean webBean) {
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if (pageContext.getParameter(EVENT_PARAM).equals("SelectAll")) {
/* 勾上所有选中的Checkbox */
am.invokeMethod("selectAll");
am.invokeMethod("selectAll");
/* 设置界面汇总字段值 */
setTotalFieldValue(pageContext, webBean);
} else if (pageContext.getParameter(EVENT_PARAM).equals("NotSelectAll")) {
setTotalFieldValue(pageContext, webBean);
} else if (pageContext.getParameter(EVENT_PARAM).equals("NotSelectAll")) {
/* 去掉所有选中的Checkbox */
am.invokeMethod("notSelectAll");
am.invokeMethod("notSelectAll");
/* 设置界面汇总字段值 */
setTotalFieldValue(pageContext, webBean);
} else if (pageContext.getParameter(EVENT_PARAM).equals("SelectRecord")) {
setTotalFieldValue(pageContext, webBean);
} else if (pageContext.getParameter(EVENT_PARAM).equals("SelectRecord")) {
/* 设置界面汇总字段值 */
setTotalFieldValue(pageContext, webBean);
}
}
setTotalFieldValue(pageContext, webBean);
}
}
(5) 测试页面