1 页面提示:
String userContent =pageContext.getParameter("HelloName"); String message = "Hello," + userContent + "!"; throw new OAException(message, OAException.INFORMATION);
2 中文乱码:
try { retStr = new String(str.getBytes("ISO-8859-1"), "gb2312"); } catch (UnsupportedEncodingException e) { OAException.wrapperException(e); }
3 String转换为Number注意要引进:
import oracle.jbo.domain.Number; new Number(Integer.parseInt(String));
4 动态增加样式:
CSSStyle style = new CSSStyle(); style.setProperty("font-color", "#FFFFCC;"); webBean.findChildRecursive("DemandQty").setAttributeValue(INLINE_STYL E_ATTR, style);
5 增加删除时的对话框提示:
AImageBean delAptitude =(OAImageBean)webBean.findChildRecursive("delAptitude"); String str =null; String javaStr =null; if(delAptitude!=null){ try { str = new String("是否要删除该条认证信息?备注为:"); str = new String(str.getBytes("ISO-8859-1"), "gb2312"); } catch (UnsupportedEncodingException e) { } //假设图标列控件的ID为:Y_REMARK 备注列控件的ID为:delAptitude delAptitude.setOnClick("javascript.:var idStr = this.id; var remarkidStr = idStr.replace('delAptitude','Y_REMARK'); var remarktext = document.getElementById(remarkidStr); if(remarktext == undefined){ remarkidStr = idStr.replace('delAptitude','N_REMARK'); remarktext = document.getElementById(remarkidStr); } var str ='"+str+"'; var str2=remarktext.innerText; var str3=str.concat(str2); if(!confirm(str3)){ return false ; }; //注意在此处要返回flase }
6 远程调用的参数传递:
Serializable[] Parameters = {SearchLogonName,SearchUserName}; //创建变量数组 am.invokeMethod("UserQuery",Parameters); //调用AM方法UserQuery
7 条件拼凑:
public void initQuery(String SearchLogonName,String SearchUserName)
{
StringBuffer WhereCluse = new StringBuffer(); //新定义一个WHERE条件的对象
Vector Parameters = new Vector(2);
int CluseCount = 0;
int BindCount = 0;
this.setWhereClauseParams(null);//以上是给对象初始化
//保存LOGONNAME
if ((SearchLogonName != null) && (!("".equals(SearchLogonName.trim()))))
{
WhereCluse.append("LOGON_NAME = :"); //增加一个字符串
WhereCluse.append(++BindCount);
Parameters.addElement(SearchLogonName);// 给BindCount赋值 用于判断
CluseCount++;
}
//保存USER_NAME
if ((SearchUserName != null) && (!("".equals(SearchUserName.trim()))))
{
if (CluseCount > 0)
{
WhereCluse.append(" AND "); //拼SQL语句
}
WhereCluse.append("USER_NAME = :");
WhereCluse.append(++BindCount);
Parameters.addElement(SearchUserName);
CluseCount++;
}
this.setWhereClause(WhereCluse.toString());
if (BindCount>0)
{
Object[] Params = new Object[BindCount];
Parameters.copyInto(Params);
setWhereClauseParams(Params);//给WHERE条件赋值
}
}
8 页面跳转:
String userid = pageContext.getParameter("userid");//获取UserId HashMap params = new HashMap(1);//创建HashMap对象 params.put("userid",userid);//给参数赋值 //跳转到修改页面,同时传递参数过去 pageContext.setForwardURL("OA.jsp?page=/oracle/apps/sie/lesson/update/webui/UpdateUserPG", null, OAWebBeanConstants.KEEP_MENU_CONTEXT, null,params,true, // Retain AM OAWebBeanConstants.ADD_BREAD_CRUMB_YES, OAWebBeanConstants.IGNORE_MESSAGES);
9 新建时序列赋值:
public void create(AttributeList attributeList) { super.create(attributeList); //修改给UserId赋值,获取序列号 Number new_user_id = this.getOADBTransaction().getSequenceValue("OAF_EXM_USER_S"); setUserId(new_user_id); }
10 删除遍历:
------------------------版本一-----------------------------
public void deleteUser()
{
OAViewObjectImpl vo =getUserSummaryVO1();
UserSummaryVORowImpl row = null;
int fetchedRowCount = vo.getFetchedRowCount(); //可用getRowCount();
RowSetIterator deleteIter = null;
try
{
deleteIter = vo.createRowSetIterator("deleteIter");
if (fetchedRowCount > 0)
{
deleteIter.setRangeStart(0);
deleteIter.setRangeSize(fetchedRowCount);
while (deleteIter.hasNext())
{
row = (UserSummaryVORowImpl)deleteIter.next();
System.out.print(row.getSelectFlag());
if (“Y”. equals(row.getSelectFlag()))
{
row.remove();
}
}
getTransaction().commit();
}
}
finally
{
if (deleteIter!=null)
{
deleteIter.closeRowSetIterator();
}
}
}
---------------------版本二-----------------------------------
private void deleteComment(int article_id) { CommentVOImpl vo=(CommentVOImpl)getCommentVO1(); CommentVORowImpl row = null; row=(CommentVORowImpl)vo.first(); while(row!=null){ Number primaryKey = row.getArticleId(); if (primaryKey.compareTo(article_id) == 0) { row.remove(); getTransaction().commit(); } if(vo.hasNext()) row=(CommentVORowImpl)vo.next(); else break; } }
11 事务开和关:
――事务新建
TransactionUnitHelper.startTransactionUnit(pageContext, "createPlanTxn"); //开启事务
――事务关闭
if (TransactionUnitHelper.isTransactionUnitInProgress(pageContext, "createUserTxn", false)) //这里是用到一个令牌效果,如果执行了从新建页面回退到此页面,才执行如下操作。判断是否有令牌
{
am.invokeMethod("cancel"); //调用AM 的cancel方法
TransactionUnitHelper.endTransactionUnit(pageContext, " createUserTxn "); //撤消创建事务
}
--处理浏览器回退
//初始化加载页面,检查是否通过浏览器回退按钮进入本页面,如果是,则报警提示用户
if (!pageContext.isBackNavigationFired(false))
{
//正常进入创建用户页面,申明创建用户事务
TransactionUnitHelper.startTransactionUnit(pageContext, " createUserTxn ");
//注册一个“createUserTxn”事务
if (!pageContext.isFormSubmission())//判断是否提交
{
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod("newUser");//调用AM的“newUser”方法
}
}
else
{
//浏览器回退钮进入,报异常信息
if (!TransactionUnitHelper.isTransactionUnitInProgress(pageContext, " createUserTxn ", true))
{
OADialogPage dialogPage = new OADialogPage(NAVIGATION_ERROR);
pageContext.redirectToDialogPage(dialogPage); //显示错误信息
}
}
12 取消,应用,增加:
//数据库的回滚
public void cancel ()
{
Transaction Txn = getTransaction();//创建对象
if (Txn.isDirty())//检查是否脏数据
{
Txn.rollback();//执行回滚
}
}
//数据库提交
public void apply () {
this.getDBTransaction().commit();//执行提交操作
}
//创建新用户
public void createNewUser()
{
UserVOImpl vo = (UserVOImpl)getUserVO1();//获取VO
vo.setMaxFetchSize(0);
vo.executeQuery();//首先必须执行VO
Row row = vo.createRow();//创建一个新行
vo.insertRow(row);//将新创建的行加入到VO里
row.setNewRowState(Row.STATUS_INITIALIZED);//给创建的新行赋类型
}
13 删除跳转页面提示:
String ctmCode = pageContext.getParameter("ctmcode");
String ctmName = pageContext.getParameter("ctmname");
String str=new String("是否确定要删除此客户信息(");
String str2=new String(")?");
try{
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
str=str+ctmCode+" "+ctmName+new String(str2.getBytes("ISO-8859-1"),"gb2312");
}catch(Exception e){}
OAException mainMessage = new OAException(str);
OADialogPage dialogPage = new OADialogPage(OAException.WARNING, mainMessage, null, "", "");
String yes = pageContext.getMessage("AK", "FWK_TBX_T_YES", null);
String no = pageContext.getMessage("AK", "FWK_TBX_T_NO", null);
dialogPage.setOkButtonItemName("DeleteYesButton");
dialogPage.setOkButtonToPost(true);
dialogPage.setNoButtonToPost(true);
dialogPage.setPostToCallingPage(true);
dialogPage.setOkButtonLabel(yes);
dialogPage.setNoButtonLabel(no);
java.util.Hashtable formParams = new java.util.Hashtable(1);
formParams.put("id", id);
formParams.put("ctmcode", ctmCode);
formParams.put("ctmname", ctmName);
dialogPage.setFormParameters(formParams);
pageContext.redirectToDialogPage(dialogPage);
}
else if (pageContext.getParameter("DeleteYesButton") != null)
{
String id = pageContext.getParameter("id");
String ctmCode = pageContext.getParameter("ctmcode");
String ctmName = pageContext.getParameter("ctmname");
Serializable[] parameters = { id };
am.invokeMethod("DeleteCtmId",parameters);//调用AM方法删除
String str=new String("已删除客户信息(");
String str2=new String(")");
try{
str=new String(str.getBytes("ISO-8859-1"),"gb2312");
str=str+ctmCode+" "+ctmName+new String(str2.getBytes("ISO-8859-1"),"gb2312");
}catch(Exception e){}
OAException message = new OAException(str,OAException.WARNING);
pageContext.putDialogMessage(message);
}
14 调用存储过程:
int user_id = Integer.valueOf(pageContext.getParameter("user_id"));
int org_id = Integer.valueOf(pageContext.getParameter("org_id"));
int mfg_org_id = Integer.valueOf(pageContext.getParameter("mfg_org_id"));
int po_line_id = Integer.valueOf(pageContext.getParameter("po_line_id"));
int po_head_id = Integer.valueOf(pageContext.getParameter("po_head_id"));
int resp_Id = Integer.valueOf(pageContext.getParameter("resp_Id"));
int resp_appl_id = Integer.valueOf(pageContext.getParameter("resp_appl_id"));
System.out.println("--start----");
String result =null;
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);
OADBTransaction transaction = null;
CallableStatement stm =null;
try{
transaction = am.getOADBTransaction();
String sql ="Begin oaf_receive_inv_pg.receive_inv( p_user_id => :1, "
+"org_id => :2 ,"
+"p_mfg_org_id=> :3,"
+"p_po_line_id=> :4,"
+"p_po_head_id=> :5,"
+"p_resp_Id=> :6,"
+"p_resp_appl_id=> :7,"
+"o_result =>:8 ); end;";
stm = transaction.createCallableStatement(sql,1);
stm.setInt(1,user_id);
stm.setInt(2,org_id);
stm.setInt(3,mfg_org_id);
stm.setInt(4,po_line_id);
stm.setInt(5,po_head_id);
stm.setInt(6,resp_Id);
stm.setInt(7,resp_appl_id);
stm.registerOutParameter(8, 12);
stm.execute();
result = stm.getString(8);
System.out.println("end:"+result);
}catch(Exception exception){
exception.printStackTrace();
} finally {
try {
if (stm != null) stm.close();
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
15 绑定下载控件,实现文件名动态改变:
OAMessageFileUploadBean ubean = (OAMessageFileUploadBean)webBean.findChildRecursive("N_ARRACH");
if(ubean != null){
OADataBoundValueViewObject kk = new OADataBoundValueViewObject(ubean,"AttachmentFilename");
ubean.setAttributeValue(DOWNLOAD_FILE_NAME,kk);
}
16 日期转换:
public String paseDate(String needByDate) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String mDateTime ="";
if(!"".equals(needByDate.trim())){
mDateTime = formatter.format(new java.util.Date(needByDate));
}
return mDateTime;
}
17 遍历VO:
方法一:
OAViewObject vo = (OAViewObject)am.findViewObject("XXVO"); Row lineVO=vo.first(); while ( lineVO != null) { //TODO lineVO = vo.next(); }
方法二:
for (Row row2 = vo.first(); row2 != null; row2 = vo.next()) { //meaning = (String)row2.getAttribute("Meaning"); //TODO }