在VO中引用Controller层中的Session State的两种方法
来源:互联网 发布:大地彩票v6 源码 编辑:程序博客网 时间:2024/05/19 00:52
http://blogs.oracle.com/smuenchadf/resource/examples中的第154个Example,Steven介绍了两种将Controller层中的值绑定给View Object中的变量的方法,其中的Session State可以理解为对应的一个Session值。
1,在adf.userSession.userData中保存Controller层传递过来的值,引用值的Groovy表达式为:adf.userSession.userData.FlavoriteColor。Steven推荐使用这种方法。
1)在Application Module中定义一个变量的Get/Set方法
public String getSessionFavoriteColor() { return (String)getDBTransaction().getSession().getUserData().get(FAVORITE_COLOR); } public void setSessionFavoriteColor(String color) { String previousFavoriteColor = getSessionFavoriteColor(); getDBTransaction().getSession().getUserData().put(FAVORITE_COLOR,color); if (valueChanged(previousFavoriteColor,color)) { getExampleVO().executeQuery(); } }2)AM中expose该Java方法
3)通过Action绑定在Managed Bean中调用
public void onFavoriteColorChanged(ValueChangeEvent valueChangeEvent) { EL.setValueChangeEventComponentToNewValue(valueChangeEvent); invokeOperationBinding("setSessionFavoriteColor"); invokeOperationBinding("Execute1"); }这种处理方法要求在创建新的AM instance的时候,要调用setSessionFavoriteColor给一个新值,否则favoriteColor只能取一个默认值。
2,在adf.context.securityContext中保存Controller层的值,引用值的Groovy表达式为:adf.context.sessionScope.UserInfo.favoriteColor。
1)定义Session Scope的managed bean
2)给Data Control定义新的Factory Class,该Factory Class创建一个CustomDCJboDataControl Factory Instance。在页面Request的时候,将Session中的值传递到AM中
public void beginRequest(HashMap requestCtx) { String favoriteColor = EL.getAsString("#{UserInfo.favoriteColor}"); super.beginRequest(requestCtx); if (favoriteColor != null) { ExampleModule am = (ExampleModule)getDataProvider(); am.setSessionFavoriteColor(favoriteColor); } }
这种处理方法只保证每次创建AM instance的时候都取Session中保存的UserInfo对应的值。
State管理:
以上两种方法都涉及到AM的State管理,在AM钝化/激活的时候,处理AM中Controller层传递过来的值,AM State management相关的知识可以参考:Fusion Developer's Guide for Oracle Application Development:Application State Mangement
@Override protected void passivateState(Document document, Element element) { System.out.println("passivate state: " + getSessionUserInfo()); element.setAttribute(USER_INFO, getSessionUserInfo()); super.passivateState(document, element); } @Override protected void activateState(Element element) { System.out.println("active state: " + element.getAttribute(USER_INFO)); super.activateState(element); setSessionUserInfo(element.getAttribute(USER_INFO)); }
拓展:
在使用ADF Security的情况下,在Model层中可以使用 adf.context.securityContext来得到Login用户的信息。ADF Security的灵活性有限,不能动态的创建角色以及角色相关联的页面信息。这时,我们会开发用户管理功能,自定义的Login页面,在用户login后,用户信息可以保存在HttpSession中或Session Scope的managed bean中,如何传递到Model层,就可以使用上面介绍的两种方法。
- 在VO中引用Controller层中的Session State的两种方法
- 在Unity中引用Dll的两种方法
- 在Unity中引用Dll的两种方法
- 在Unity中引用Dll的两种方法
- 在Unity中引用Dll的两种方法
- Java2EE的controller层获取session的方法
- java 在主程序中添加和引用自定义程序的两种方法(主类中的static方法和其他类中的普通方法)
- SpringMVC中controller返回json数据的两种方法
- Session在Controller中的传递
- 关于mvc中的session在controller中传递
- 在controller中获取不到的session值中的验证码问题
- Struts2 中action中获取session的两种方法
- SpringMVC在Controller层中注入request的坑
- SpringMVC在Controller层中注入request的坑
- 如何在SpringMVC 的@Controller 层中获取bean
- SpringMVC在Controller层中注入request的坑
- SpringMVC在Controller层中注入request的坑
- Struts2中使用Session的两种方法
- 登陆csdn 1000次
- 链表常用操作 (定义,创建,反转,合并,交叉)
- GetCurrentThread() returns pseudo handle, not the real handle.
- 【Android】提高Adapter的效率
- priority_queue例子
- 在VO中引用Controller层中的Session State的两种方法
- hdoj 1035(算是水题把)(屏蔽freopen)
- 莫让代码腐化:让营地比你来时更干净
- 项目管理: Maven 让事情变得简单--给您的下一个 Java 构建添加项目管理特性
- hdu1176免费馅饼
- Linuxx下printf格式符%d、%lld、%llx、%u等
- 与九期一起装系统(共同提高)
- Python数据类型——数值类型
- Python数据类型——序列(字符串,列表,元组)