使用场景
获得当前事件对象
本次请求request
直接使用变量【kdevent.getReqeustContext().getHttpServletRequest()】
本次请求response
直接使用变量【kdevent.getResponseContext().getHttpServletResponse()】
上下文内容
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.bos.webframework.context);
imp.importPackage(Packages.com.kingdee.eas.base.permission);
imp.importPackage(Packages.com.kingdee.eas.common);
imp.importPackage(Packages.com.kingdee.eas.basedata.org);
with(imp){
var ctx = WafContext.getInstance().getContext();
//当前用户
var user =(UserInfo)ctx.get(SysContextConstant.USERINFO);
//当前组织
var curOU = (OrgUnitInfo) ctx.get("CurOU");
//当前CU
var cu =(OrgUnitInfo) ctx.get(OrgType.ControlUnit);
//当前财务组织
var company = (OrgUnitInfo) ctx.get(OrgType.Company);
//其他类型类似
}
获得URL中的参数
var imp=JavaImporter();
imp.importPackage(Packages.javax.servlet.http);
with(imp){
HttpServletRequest request = event.getReqeustContext().getHttpServletRequest();
var uipk = request.getParameter("uipk");
var action = request.getParameter("action");
}
获得doPost中data中数据
var imp=JavaImporter();
imp.importPackage(Packages.javax.servlet.http);
with(imp){
var dataParam = request.getParameter("直接使用data中的json对象属性名称");
}
调用类静态方法
var imp=JavaImporter();
imp.importPackage(Packages.类所在包名);
with(imp){
类名.方法名();
}
调用类的方法
var imp=JavaImporter();
imp.importPackage(Packages.类所在包名);
with(imp){
var tempClass =new 类名();
tempClass.方法名();
}
调用当前实体对应的ControllerBean接口
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.application);
with(imp){
var bizCtrl = ApplicationSessionContext.getApplication().getModelService().getBizInterface(ctx);
var xxxInfo = bizCtrl.getValue(new ObjectUuidPK("具体id字符串"));
}
调用BIM定义的ControllerBean接口
var imp=JavaImporter();
imp.importPackage(Packages.app类所在包名);
imp.importPackage(Packages.com.kingdee.bos.dao.ormapping);
with(imp){
//调用BIM定义的ControllerBean
var ctx = WafContext.getInstance().getContext();
var iXXX = XXXFactory.getLocalInstance(ctx);
var xxxInfo = iXXX.getValue(new ObjectUuidPK("具体id字符串"));
}
调用DEP定义的ControllerBean接口
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.eas.ep);
imp.importPackage(Packages.com.kingdee.bos.metadata);
with(imp){
var iBosObject = BOSObjectFactory.createCommonBOSObject(ctx,new MetaDataPK("实体的元数据名称"));
var info = iBosObject.getValue(new ObjectUuidPK("具体id字符串"));
}
调用Facade接口
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.bos.util);
imp.importPackage(Packages.app类所在包名);
with(imp){
var ctx = WafContext.getInstance().getContext();
var xxxFacade = XxxFacadeFactory.getLocalInstance(ctx);
var result = xxxFacade.method(参数列表);
}
触发另外一个后台事件
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.application);
with(imp){
var eventBus = ApplicationSessionContext.getApplication().getEventBus();
eventBus.fireEvent(new 事件名());
}
异常的处理
var imp=JavaImporter();
imp.importPackage(com.kingdee.bos.webframework.exception);
imp.importPackage(com.kingdee.bos.webframework.util);
with(imp){
RhinoUtils.toThrow(new WafException("具体错误信息"));
}
直接数据库处理
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.eas.util.app);
with(imp){
//查询
var rowset = DbUtil.executeQuery(ctx, "sql");
while (rowset.next()){
var number = rowset.getString("字段名");
}
//执行
DbUtil.execute(ctx, "sql");
}
ajax调用返回成功值
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.bos.webframework.json);
with(imp){
JSONUtils.SUCCESS(结果对象);
}
重定向
var imp=JavaImporter();
with(imp){
event.getResponseContext().setRedirectUrl("URL相对路径");
}
一个完整的实现例子
var imp=JavaImporter();
imp.importPackage(Packages.com.kingdee.eas.custom);
imp.importPackage(Packages.java.lang);
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.bos.webframework.context);
imp.importPackage(Packages.com.kingdee.eas.base.permission);
imp.importPackage(Packages.com.kingdee.eas.common);
imp.importPackage(Packages.com.kingdee.eas.basedata.org);
imp.importPackage(Packages.javax.servlet.http);
imp.importPackage(Packages.com.kingdee.eas.util.app);
imp.importPackage(Packages.com.kingdee.eas.basedata.assistant);
imp.importPackage(Packages.com.kingdee.bos.dao.ormapping);
imp.importPackage(Packages.com.kingdee.bos);
imp.importPackage(Packages.com.kingdee.eas.ep);
imp.importPackage(Packages.com.kingdee.bos.metadata);
imp.importPackage(Packages.com.kingdee.bos.util);
imp.importPackage(Packages.com.kingdee.eas.basedata.person);
imp.importPackage(Packages.com.kingdee.bos.webframework.exception);
imp.importPackage(Packages.com.kingdee.bos.webframework.util);
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.application);
imp.importPackage(Packages.com.kingdee.bos.webframework.dynamic.event.view);
imp.importPackage(Packages.com.kingdee.bos.webframework.json);
with(imp){
//本次请求request
var request = kdevent.getReqeustContext().getHttpServletRequest();
//本次请求response
var response = kdevent.getResponseContext().getHttpServletResponse();
//上下文内容
var ctx = WafContext.getInstance().getContext();
var user =ctx.get(SysContextConstant.USERINFO);
var curOU = ctx.get("CurOU");
var cu = ctx.get(OrgType.ControlUnit);
var company = ctx.get(OrgType.Company);
System.out.println("From Rhino:UserName"+user.getName());
System.out.println("From Rhino:OrgName"+curOU.getName());
System.out.println("From Rhino:ComanyName"+company.getName());
//获得URL中的参数
var uipk = request.getParameter("uipk");
var action = request.getParameter("action");
System.out.println("From Rhino:uipk"+uipk);
System.out.println("From Rhino:action"+action);
//获得doPost中data中数据
var dataPara1 = request.getParameter("dataPara1");
var dataPara2 = request.getParameter("dataPara2");
System.out.println("From Rhino:dataPara1"+dataPara1);
System.out.println("From Rhino:dataPara2"+dataPara2);
//调用类静态方法
TestRhinoStatic.test(kdevent);
//调用类方法
var test = new TestRhino();
var temp = test.test(kdevent);
System.out.println("From Rhino:class result"+temp);
//直接数据库处理
var rowset = DbUtil.executeQuery(ctx, "select * from ct_my_vehicle");
while (rowset.next()){
var number = rowset.getString("fnumber");
var name = rowset.getString("fname_l2");
System.out.println("From Rhino:ct_my_vehicle'number"+number);
System.out.println("From Rhino:ct_my_vehicle'name"+name);
}
//调用当前实体的ControllerBean
var bizCtrl = ApplicationSessionContext.getApplication().getModelService().getBizInterface(ctx);
var carBrand1 = bizCtrl.getValue(new ObjectUuidPK("8dDe33nBT9S5Cud5mC02ZjufbZs="));
System.out.println("From Rhino:CarBrand1'name"+carBrand1.get("name"));
System.out.println("From Rhino:CarBrand1'number"+carBrand1.get("number"));
//调用ControllerBean接口
var city = CityFactory.getLocalInstance(ctx);
var cityInfo = city.getValue(new ObjectUuidPK("6a05bcad-00fd-1000-e000-01f2c0a8100d0C5DD6B6"));
System.out.println("From Rhino:cityInfo"+cityInfo.getName());
//调用DEP定义的后台
var iBosObject = BOSObjectFactory.createCommonBOSObject(ctx,new MetaDataPK("com.kingdee.eas.base.myeas.app.CarBrand"));
var carBrand = iBosObject.getValue(new ObjectUuidPK("8dDe33nBT9S5Cud5mC02ZjufbZs="));
System.out.println("From Rhino:CarBrand'name"+carBrand.get("name"));
System.out.println("From Rhino:CarBrand'number"+carBrand.get("number"));
//调用Facade
var personFacade = PersonFacadeFactory.getLocalInstance(ctx);
var result = personFacade.getUserByPerson(BOSUuid.read("e74AAAACbL+A733t"));
System.out.println("From Rhino:Facade Result"+result);
//抛个异常,后续就不会再执行了
//RhinoUtils.toThrow(new WafException("出错了1!"));
//调用后台事件
try{
var eventBus = ApplicationSessionContext.getApplication().getEventBus();
eventBus.fireEvent(new PermissionFunctionCheckEvent());
}
catch(e){
System.out.println("From Rhino:Exception"+e);
}
//返回调用成功结果
JSONUtils.SUCCESS("good");
}