2012年8月9日星期四

ADF_193:Task Flow使用指南之七:SavePoints(2)

运行环境:JDeveloper 11.1.1.1.6 + Oracle Database 10g Express Edition 10.2.0.1。

上一个实验使用的是EL表达式:#{controllerContext.savePointManager.createSavePoint}创建SavePoints。
本实验使用Java Method创建SavePoints,并且使用下拉列表显示所有的SavePoints,用户可以选择Restore哪一个SavePoint。


完整的Managed Bean代码如下:

package view;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import oracle.adf.controller.ControllerContext;
import oracle.adf.controller.savepoint.SavePointAttributes;
import oracle.adf.controller.savepoint.SavePointManager;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;

import oracle.adf.model.binding.DCIteratorBinding;
import oracle.adf.share.ADFContext;

import oracle.adf.view.rich.component.rich.data.RichTable;

import oracle.binding.BindingContainer;

import oracle.jbo.Row;

public class MyBackingBean {
private ControllerContext cc;
private SavePointManager spm;

public MyBackingBean() {
cc = ControllerContext.getInstance();
spm = cc.getSavePointManager();
}

public List getSavepoints() {
List options;
options = new ArrayList();
List saves = spm.listSavePointIds();
SelectItem option;
for (int i = 0; i < saves.size(); i++) {
SavePointAttributes att = spm.getSavePointAttributes(saves.get(i));
option =
new SelectItem(saves.get(i), saves.get(i) + "_" + att.getName());
options.add(option);
}
return options;
}

public void clearSavepoints(ActionEvent actionEvent) {
spm.clearSavePoints();
}

public void createSavePoint() {
String saveId =
spm.createSavePoint(new SavePointAttributes("Employee", "Employee's Save Point",
null));
System.out.println("##### Save point is being set " + saveId);
ADFContext.getCurrent().getPageFlowScope().put("savePointId", saveId);
}

public Map getCurrentEmployeeInfo() {
Map map = new HashMap();
DCBindingContainer bindings = (DCBindingContainer)getBindings();
DCIteratorBinding dcIb =
bindings.findIteratorBinding("EmployeesView1Iterator");
Row row = dcIb.getCurrentRow();
map.put("EmployeeId", row.getAttribute("EmployeeId"));
map.put("DepartmentId", row.getAttribute("DepartmentId"));
return map;
}

public BindingContainer getBindings() {
return BindingContext.getCurrent().getCurrentBindingsEntry();
}
}


Project 下载:ADF_TaskFlow_SavePoints_Explicit(2).7z

没有评论: