/*OAF控件及常见问题使用
OAF 东方瀚海
http://fccjxxw.com/m/b071defc4afe04a1a8ede1b4.html**/
参考博客:http://hutianci.iteye.com/blog/1015925
(1)在前台第一次进页面初始化时存值获取[在控件formValue存执]*/
OAFormValueBean oucdValue =
(OAFormValueBean)webBean.findChildRecursive("oucd");
oucdValue.setValue(pageContext, oucd);
/*(2)在后台第一次进页面初始化时存值获取:TransientValue是支持久化在本地JVM,
不会跨JVM持久化或Servlet Session范围保存。当root appliction module被回收
时,TransientValue会丢失*/
pageContext.putTransactionTransientValue("oucdValue",oucd);
String oucdValue =pageContext.getTransactionTransientValue("oucdValue").toString();
(3)设置全局变量(在类下设置)
if ("changeList".equals(event)) {
OAMessageChoiceBean totalInv =
(OAMessageChoiceBean)webBean.findChildRecursive("totalInv");
String selectValue = totalInv.getSelectionValue(pageContext);
Serializable[] parameters = { selectValue };
am.invokeMethod("handleListChangeEvent", parameters);
}
//lovValidate手动修改Lov值时(点击别处时)触发事件
//lovUpdate从选择页面回主页面时触发事件
if ("lovUpdate".equals(event)) {
String lovInputSourceId =
pageContext.getParameter(SOURCE_PARAM); //ID获取当前点击Lovinput控件的id
if("categoryLovInput".equals(lovInputSourceId)) {
......
}
}
if ("lovPrepare".equals(event)) {
// txtSearch 为 LovInput 的条件框
OAFormValueBean txtSearch =
(OAFormValueBean)webBean.findChildRecursive("category");
// 设置 名称为 categoryClass 的 AM 参数 用于 传递到 LovInput的 page 页面中
((OADBTransaction)am.getTransaction()).putTransientValue("category",
txtSearch.getText(pageContext));
}
//在 LovInput Page 的CO 中processRequest 添加
//获取刚刚从主页面设置的 参数
String txtSearch =
(String)pageContext.getTransactionTransientValue("category");
以类别和等级为例:其中只要类别为Lov时,可以在类别lovMapping下的lovMap对应
LOV Region Item设置值为:ParentFlexValueLow,
Criteria Item值设置为:对类别Id,
设置Programmatic Query设置为:True
OADefaultHideShowBean hideShow1 =
(OADefaultHideShowBean)webBean.findChildRecursive("hideShow1");
hideShow1.setDefaultDisclosed(pageContext,false);
(如果是利用其他控件进行控制,则需要进行刷新页面)
注意:此处不是OAHideShowBean类、对应属性设置也不是setDisclosed
String[] departs = {"departmentCho"};
HashMap dpts =CustomSearchUtil.getBeanValues(pageContext,webBean,departs);
String departments = dpts.get("departmentCho")+"";
3、控件
public static HashMap getBeanValues(OAPageContext pageContext, OAWebBean webBean,
String[] strWebBeanNames)
{
HashMap searchMap = new HashMap();
if (strWebBeanNames != null)
{
OAWebBean itemWebBean =null;
for (int i = 0; i
//Search for Bean
itemWebBean =webBean.findChildRecursive(strWebBeanNames[i]);
Object valueStr = null;
String value = "";
if (itemWebBean !=null)
{
//OAMessageTextInputBean
if(itemWebBean instanceof OAMessageTextInputBean)
{
valueStr =((OAMessageTextInputBean)itemWebBean).getValue(pageContext);
//((OAMessageTextInputBean)itemWebBean).setValue(pageContext, null);
}
//OAMessageLovInputBean
else if(itemWebBean instanceof OAMessageLovInputBean)
{
valueStr = ((OAMessageLovInputBean)itemWebBean).getValue(pageContext);
//((OAMessageLovInputBean)itemWebBean).setValue(pageContext, null);
}
//OAMessageLovChoiceBean
else if ((itemWebBean instanceofOAMessageLovChoiceBean))
{
valueStr = ((OAMessageLovChoiceBean)itemWebBean).getValue(pageContext);
//((OAMessageLovChoiceBean)itemWebBean).setValue(pageContext,null);
}
//OAMessageChoiceBean
else if(itemWebBean instanceof OAMessageChoiceBean)
{
valueStr = ((OAMessageChoiceBean)itemWebBean).getValue(pageContext);
//((OAMessageChoiceBean)itemWebBean).setValue(pageContext, null);
}
//OAMessageDateFieldBean
else if(itemWebBean instanceof OAMessageDateFieldBean)
{
valueStr =((OAMessageDateFieldBean)itemWebBean).getValue(pageContext);
//((OAMessageDateFieldBean)itemWebBean).setValue(pageContext, null);
}
//OAFormValueBean
else if(itemWebBean instanceof OAFormValueBean)
{
valueStr =((OAFormValueBean)itemWebBean).getValue(pageContext);
//((OAFormValueBean)itemWebBean).setValue(pageContext, null);
}
//OAMessageCheckBoxBean
else if (itemWebBeaninstanceof OAMessageCheckBoxBean)
{
valueStr =((OAMessageCheckBoxBean)itemWebBean).getValue(pageContext);
//((OAMessageCheckBoxBean)itemWebBean).setValue(pageContext, null);
} else
{
thrownew OAException("Not Found the webBean");
}
}
if (null != valueStr) {
value = valueStr.toString();
} else {
value = "";
}
if (!isStrNull(value)) {
searchMap.put(strWebBeanNames[i], value);
}
}
}
return searchMap;
}
//OAF对隐藏控件清空控件值(保证不刷新页面)
清空控件为button,并且绑定局部事件clearBtn
1、点击清空时触发事件clearBtn(清空请求里的值)
String[] clearBeanNames =
{ "testDateFrom", "testDateTo" };
CustomSearchUtil.resetWebBean(pageContext, webBean, clearBeanNames);//参考 动态控件值的获取
2、在button上写JS事件//参考 OAF注册JS事件
jsString.append("lovClearValue(document.DefaultFormName." +
webBeanClearNames[i] + ");");
OAMessageDateFieldBean sendDate =
(OAMessageDateFieldBean)webBean.findChildRecursive("sendDate");
String sendDates = null;
Object obj =sendDate.getValue(pageContext);
if(null!=obj){
sendDates =obj.toString();
}
Date date = new Date();
sendDate.setValue(pageContext, date);
触发函数:changeBeanStatusJS(pageContext,webBean, "warehouse");
//效果:
//仓库过滤条件,若选择109北京卷烟厂,110天津卷烟厂,111高扬自营,则审核按钮不可见,
//"审核标记"默认为"审核"
public void changeBeanStatusJS(OAPageContextpageContext,
OAWebBean webBean, String beanName) {
StringBuffer jsStr = new StringBuffer();
jsStr.append(" function changeBeanStatusJS(){ ");
//下拉框赋值(展示值):OAF下拉框对应Code值不是页面代码下拉框对应value值(其为加密形成的value值[一直变化的值])******
jsStr.append("document.getElementById('formStatus').selectedIndex = 0;");
//对于页面刷新时还存在的展示删除方式(textarea属性rows行从0开始cells列从0开始)
jsStr.append(" var wareVal = document.getElementById('categoryLov').rows[1].cells[19].innerHTML = '';");
jsStr.append(" var wareVal = document.getElementById('warehouseval').value;");
jsStr.append(" wareVal = wareVal.substring(0,3); "); //只取前三位,不知道formvalue这个控件什么原因字符串多了
jsStr.append(" if( wareVal=='109' || wareVal=='110' ||wareVal=='111' ) { ");
jsStr.append(" document.getElementById('Check').style.display ='none'; "); //设置不可见
jsStr.append("document.getElementById('checkTag').options[1].selected=true; "); //选择1已审核
jsStr.append(" document.getElementById('checkTag').disabled = true;");
jsStr.append(" }else{ ");
jsStr.append(" document.getElementById('Check').style.display = '';"); //设置可见
jsStr.append(" document.getElementById('checkTag').disabled =false; ");
jsStr.append(" } ");
jsStr.append(" } ");
//此为加载页面时就添加JS函数
//OABodyBean bodyBean = (OABodyBean)pageContext.getRootWebBean();
OAMessageLovInputBean warehouse =
(OAMessageLovInputBean)webBean.findChildRecursive(beanName);
pageContext.putJavaScriptFunction("changeBeanStatusJS",
jsStr.toString());
if (warehouse != null) {
//非空值触发JS函数
warehouse.setOnFocus("javascript:changeBeanStatusJS();");
}
}
//SimpleDateFormat df = newSimpleDateFormat("yyyy-MM-dd");用此转换时间格式
ID:wareHouseLovCho
External LOV:对应关联的RN
Picklist Display Attribute和Picklist Value Attribute配置
在对应的lovMap中
LOV Region Item:对应RN里的Code值
Return Item:上面的ID值
6、勾选框(messagecheckBox)设置问题:页面跳转手动设置
Initial Value设值一般为on
Checked Value设值一般为on
在页面跳转前设值为:
//勾选框不进行设置,在勾选值去掉后,value有时还是为勾选时的值
Object value =pageContext.getParameter("checkFlag");
String flags = "";
if (value != null &&"on".equals(value.toString())) {
flags = "on";
} else if (value == null) {
flags = "";
}
两个messageRadioButton
设置为:Initial Value、Checked Value设置值相同1
Unchecked Value设置值0
另外一个相反
一个messageRadioGroup
不需要进行设置
OASubTabLayoutBean subTableLayOut=(OASubTabLayoutBean)webBean.findChildRecursive("SubTabRN");
if (app_prop_code != null&& !("".equals(app_prop_code.trim())) &&
("储运转烟厂高扬".equals(app_prop_code))) {
subTableLayOut.hideSubTab(0, true);
subTableLayOut.hideSubTab(2, false);
subTableLayOut.hideSubTab(3, false);
subTableLayOut.setSelectedIndex(pageContext, 2);
} else {
subTableLayOut.hideSubTab(0, false);
subTableLayOut.hideSubTab(2, true);
subTableLayOut.hideSubTab(3, true);
subTableLayOut.setSelectedIndex(pageContext, 0);
//此方法返回对应的Tab序列,可以放在processFormRequest中
//多个按钮修改Tab展示第几个stackLayout方法
//获取当前Tab位置(0,1,2)
int i = subTableLayOut.getSelectedIndex(pageContext);
Tab跳转:
1、processFormRequest方法中赋值:(value1...N)
pageContext.putParameter("tabKey","valueN");
2、processRequest方法中拿值:
String tabKey =pageContext.getParameter("tabKey");
3、processRequest方法中比较:
//从查询tab跳转至明细tab
if ("valueN".equals(tabKey)) {
subTabLayout.setSelectedIndex(pageContext, 1);
}
OAStackLayoutBean sumSubLayout =
(OAStackLayoutBean)webBean.findChildRecursive("SumSub");
sumSubLayout.addIndexedChild(pdfElement);
//之前为pageContext.getPageLayoutBean().addIndexedChild(pdfElement);
(Tab中控制页面跳转时初始值赋值不改变:在对应的Link上绑定事件进行控制)
//AM中获取当前时间
this.getOADBTransaction().getCurrentDBDate();
/**获取会计日期,//row.setAttribute只能是sql.Date类型
* @param orgIds
*/
private Date getCountDate(StringorgIds) {
String sqlStr ="{? = call cux_common_yy_pkg.get_account_date(?)}";//函数(有返回值)
//或是
//String backStr =
//" begin cux_inv_inv073_pkg.validate_sedaccount
//(p_account_date => :1, x_rs_flag => :2,x_rs_msg => :3); end; ";(过程,通过OUT实现返回值)
//String x_succ_flag= "";
//String x_error_msg= "";
CallableStatementproc = null;
Date curDate = null;
OADBTransaction tr =getOADBTransaction();
proc =tr.createCallableStatement(sqlStr, 1);
try {
//注册返回类型
proc.registerOutParameter(1, Types.DATE);
//statement.registerOutParameter(2, Types.VARCHAR);
//statement.registerOutParameter(3, Types.VARCHAR);
proc.setString(2, orgIds);
proc.execute(); //执行
//proc.executeQuery此为结果集ResultSet
curDate = proc.getDate(1); //获取结果(必须在关闭前获取数据,关闭不能正常获取数据)
//x_succ_flag = statement.getString(2);
//x_error_msg = statement.getString(3);
proc.close();
} catch(SQLException e) {
thrownew OAException("执行存储过程出现错误:" + sqlStr, OAException.ERROR);
}
return curDate;
}
//VO中根据字段是否正负显示 盈亏
DECODE((SIGN(InventoryProfitlossDetEO.PROFITLOSSWEIGHT)),-1, '盘亏', '盘盈') AS PROFITLOSSDS
//LOV对应RN的CO查询功能中有OR时需要加()
vo.setWhereClause(" ( ATTRIBUTE1 in('2','4') or code in ('104','106')) ");
//如再有输入数据,默认以AND连接ATTRIBUTE1in ('2','4') or code in ('104','106') AND[这样有问题]
/**查询条件时间格式两种*/
reportDate>=fnd_conc_date.string_to_date('2015-09-09')//即把字符串值转换为OAF认知的时间值
trunc(reportDate)<=to_date('2015-09-09','yyyy-MM-dd')//trunc(sysdate)返回今天的日期值
Formatter numForm = new OADecimalValidater("0.00", "0.00");
//OADateValidater dateForm = new OADateValidater("yyyy-MM-dd", "");
OAWebBean abl = webBean.findChildRecursive("weightPer");
if (null != abl){
if (abl instanceof OAMessageStyledTextBean) {
((OAMessageStyledTextBean)abl).setAttributeValue(ON_SUBMIT_VALIDATER_ATTR,
numForm);
} else if (abl instanceof OAMessageTextInputBean) {
((OAMessageTextInputBean)abl).setAttributeValue(ON_SUBMIT_VALIDATER_ATTR,
numForm);
}
}
1、MonWastageSumVO1为table名称
2、Totalloss对应table总计字段名称
3、bValues是赋给总计的值,具体格式要自己设置好后传过来
OATableBean table =
(OATableBean)webBean.findIndexedChildRecursive("MonWastageSumVO1");
OAWebBean abl =table.findIndexedChildRecursive("Totalloss");
//bValues:为格式化后的
if (null != abl){
if (abl instanceof OAMessageStyledTextBean) {
((OAMessageStyledTextBean)abl).setAttributeValue(TABULAR_FUNCTION_VALUE_ATTR,
bValues);
} else if (abl instanceof OAMessageTextInputBean) {
((OAMessageTextInputBean)abl).setAttributeValue(TABULAR_FUNCTION_VALUE_ATTR,
bValues);
}
}
if ("pageNumEvent".equals(event)) {//在对应下拉框设置事件
String[] tableNames = {"BtnAccountTable" };//表格ID值***
CommonUtils.setPageNumbers(pageContext, webBean, tableNames,
"pageNumChoice");
//执行一次查询
BtnAccountVOImpl vo =
(BtnAccountVOImpl)am.findViewObject("BtnAccountVO1");
if (vo.getFetchedRowCount() > 0) {
vo.executeQuery();
//显示缓存中总条数
vo.getRowCount();
}
}
//具体方法
public static void setPageNumbers(OAPageContextpageContext, OAWebBean webBean,
String[] tableNames, String pageNumChoice) {
//默认20
int num = 20;
String pageNum = pageContext.getParameter(pageNumChoice);
if (null != pageNum && !"".equals(pageNum.trim())) {
num = Integer.parseInt(pageNum);
}
if (null != tableNames) {
for (String tableName: tableNames) {
//获得Table控件***
OATableBean mainTable =
(OATableBean)webBean.findChildRecursive(tableName);
if (null != mainTable) {
//设置对应一页多少条数据***
mainTable.setNumberOfRowsDisplayed(num);
}
}
}
}
1、在表格VO中设置
decode(ProduceTobacooDetEO.CONSUMETYPE, 1,'left', 10, 'left', 'right') AS halign
2、在字段上层加rowLayout(ID值为'region33')
3、在初始化方法processRequest里加
OARowLayoutBean rowLB = (OARowLayoutBean)webBean.findIndexedChildRecursive("region33");
if(null!=rowLB){
rowLB.setAttributeValue(UIConstants.H_ALIGN_ATTR,newOADataBoundValueViewObject(rowLB,"Halign"));
}
-----在EO中注意是否有ROWID字段,否则在建VO时一直会有报错-----
if (value != null &&value.toString().matches("^[0-9]*\\.[0-9]{6,99}$")) {
Number value = new Number();(得导入import oracle.jbo.domain.Number;才不会报错在OAF中,在MyEclipse不行)
String str = value.toString().substring(0, value.toString().split("\\.")[0].length()+ 6);//加个判断若输入大于5位小数保留5位小数
value = value.subtract(value).add(Double.parseDouble(str));
-----根据条件隐藏控件三步走PVO*****
//初始化
am.invokeMethod("init"); //初始化PVO
public void init() {
OAViewObject appPropsVO =(OAViewObject)findViewObject("SumInvPLPVO1");
if (appPropsVO != null) {
if (appPropsVO.getFetchedRowCount() == 0) {
appPropsVO.setMaxFetchSize(0);
appPropsVO.executeQuery();
appPropsVO.insertRow(appPropsVO.createRow());
OARow row = (OARow)appPropsVO.first();
row.setAttribute("RowKey", new Integer(1));
}
}
}
//一定条件后
btnValue = "1,2,3,4,5";
Serializable[] paraBtn = { btnValue };
am.invokeMethod("initBtn", paraBtn);
public void initBtn(String btnValue) {
String[] btns = btnValue.split(",");
for (int i = 0, k = btns.length; i < k; i++) {
OAViewObject vo =(OAViewObject)findViewObject("SumInvPLPVO1");
OARow row = (OARow)vo.first();
if ("1".equals(btns[i])) {
row.setAttribute("makeSumRender",Boolean.TRUE);
continue;
} else if ("2".equals(btns[i])) {
row.setAttribute("cancelSumRender",Boolean.TRUE);
continue;
}
}
}
Rendered上绑定:${oa.SumInvPLPVO1.cancelSumRender}
//报表展示(第一个方法里加载)
//把报表加载到特定Tab页下
OAStackLayoutBean sumSubLayout =
(OAStackLayoutBean)webBean.findChildRecursive("SumSub");
/**参数名称要和报表里参数一样*/
String[] paramsName ={"attr1","attr2","attr3","attr4"}
String[] paramsValues = {attr1,attr2,attr3,attr4}
//显示报表:参数传递FineReport的模板参数
//(1)
OAHTMLWebBean pdfElement =
(OAHTMLWebBean)createWebBean(pageContext, HTML_WEB_BEAN, null,
"IFRAME");
//(2)
FineReportUtil.genFineReportIframe(pdfElement,"INV031",
paramsName, paramsValues, true);
//把报表加载到特定Tab页下
sumSubLayout.addIndexedChild(pdfElement);
/**在一般页面加载
pageContext.getPageLayoutBean().addIndexedChild(pdfElement);
*/
/**把报表加载到特定的header下*/
//根据ID值获取header控件
OAHeaderBean header =
(OAHeaderBean)webBean.findChildRecursive("reportHdr");
//把报表加载到特定header页下
header.addIndexedChild(pdfElement);