วันพุธที่ 7 มกราคม พ.ศ. 2558

OAF: วิธีการใส่ Format ให้กลับจำนวนเงิน

เจอปัญหาในการใส่ Format ให้กับจำนวนเงิน สำหรับ Total Row ใน OAAdvancedTable


OAAdvancedTable
Id: showDetailTb

Id: column1
Total Value: True

Id: TrxAmount
View Attribute: TrxAmount

ถึงเราจะใส่ Format ให้กับ OAMessagedStyledTextBean id TrxAmount
Formatter formatter = new OADecimalValidater("#,###,###,##0.00,(#,###,###,##0.00)", "#,###,###,##0.00;(#,###,###,##0.00)");
OAAdvancedTableBean adTable = (OAAdvancedTableBean) webBean.findChildRecursive("showDetailTb");
OAMessageStyledTextBean trxAmountTotal = (OAMessageStyledTextBean) adTable.findChildRecursive("TrxAmount");
trxAmountTotal.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);
แต่จำนวน Total ก็ยังไม่อยู่ในรูป Format
หลังจากลองผิดลองถูก เข้าไป set format ในเกือบทุก objects ที่อยู่ภายใต้ OAAdvancedTable 
ก็ได้เข้าใจว่าถ้าต้องการให้เลขใน TotalRow อยู่ในรูปแบบที่จัด Format แล้วเราต้องไปตั้งค่าที่...

เราต้องไปตั้งค่าในส่วนของ Column ที่จะแสดง ค่า Total ซึ่งในตัวอย่างนี้คือ column1  

Formatter formatter = new OADecimalValidater("#,###,###,##0.00;(#,###,###,##0.00)", "#,###,###,##0.00;(#,###,###,##0.00)");
OAAdvancedTableBean adTable = (OAAdvancedTableBean) webBean.findChildRecursive("showDetailTb");
OAMessageStyledTextBean trxAmountTotal = (OAMessageStyledTextBean) adTable.findChildRecursive("TrxAmount");
trxAmountTotal.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);
OAColumnBean column1 = (OAColumnBean) adTable.findChildRecursive("column1");
if (column1 != null) {
column1.setAttributeValue(CURRENCY_CODE, "USD");
column1.setAttributeValue(ON_SUBMIT_VALIDATER_ATTR, formatter);
}

เมื่อ Set format ให้กับ column1 แล้ว Total Row จะอยู่ในรูปของตัวเลขที่ Format เรียบร้อย