ADF中获取当前Task Flow的ID
8:38 am in Oracle 融合中间件 by Eleven.Xu
概述
Task-Flow在ADF应用中被广泛应用,而在实际开发过程中,有时会需要知道当前页面所在的Task-Flow种类甚至ID。
在Backing Bean中获取该ID的方法是非常简便的,代码如下:
1 2 | ViewPortContext ctx = ControllerContext.getInstance().getCurrentViewPort(); TaskFlowId id = ctx.getTaskFlowContext().getTaskFlowId(); |
如果想在页面中使用该ID,也可以使用EL表达式进行绑定,代码如下:
1 | #{controllerContext.currentViewPort.taskFlowContext.taskFlowId} |
下面将通过具体的实例来详细阐述获取页面当前Task-Flow ID的方法。
实现
1、创建ADF应用
2、在ViewController项目中创建bounded-task-flow,在该Task-Flow中创建view,名为bounded,并双击产生页面,为方便处理,在生成页面的同时产生出页面的Backing Bean。
3、在页面中添加按钮,为其添加Action,在该Action中添加如下代码:
1 2 3 4 5 6 7 8 9 10 | public String cb1_action() { ViewPortContext ctx = ControllerContext.getInstance().getCurrentViewPort(); TaskFlowId id = ctx.getTaskFlowContext().getTaskFlowId(); if (id != null) { System.out.println("I am in bounded task-flow"); } else { System.out.println("I am in unbounded task-flow"); } return null; } |
4、在页面中添加output label,设置其绑定为:
1 | TaskFlowId: #{controllerContext.currentViewPort.taskFlowContext.taskFlowId} |
5、在adfc-config.xml中创建view,名为unbounded,同时将步骤2中创建成功的bounded-task-flow作为taskflow call添加到adfc-config中,设置完应如图:
6、双击产生unbounded页面,生成页面的同时产生Backing Bean,在页面中添加按钮,设置其Action,在Action中添加如下代码:
1 2 3 4 5 6 7 8 9 10 | public String cb1_action() { ViewPortContext ctx = ControllerContext.getInstance().getCurrentViewPort(); TaskFlowId id = ctx.getTaskFlowContext().getTaskFlowId(); if (id != null) { System.out.println("I am in bounded task-flow"); } else { System.out.println("I am in unbounded task-flow"); } return null; } |
7、在页面中添加output label,设置其绑定为:
1 | TaskFlowId: #{controllerContext.currentViewPort.taskFlowContext.taskFlowId} |
8、运行应用,结果如下:
1)unbounded:
由于是unbounded task flow,因此TaskFlowId为空
点击"Unbounde:Where am I?"按钮
2)bounded:
TaskFlowId不为空,且为该bounded task flow的ID
点击"Bounded: Where am I?"按钮
详细的代码请查看:howtocurrenttaskflow.rar
相关文章:
One Comment