ADF backing Bean中常用的代码

来源:互联网 发布:北京学化妆 知乎 编辑:程序博客网 时间:2024/05/16 14:21

Bean中常用方法:

1
2
3
//获取binding容器
BindingContainer bindings
       =  BindingContext.getCurrent().getCurrentBindingsEntry();
1
2
3
//获取Page definitions的 attribute的值
AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("test");
attr.setInputValue(”test”);
1
2
3
4
5
6
7
8
9
// 获取action或者方法
OperationBinding method = bindings.getOperationBinding("methodAction");
method.execute();
List errors = method.getErrors();

method = bindings.getOperationBinding(”methodAction”);
Map paramsMap = method.getParamsMap();
paramsMap.put(”param”,”value”)  ;
method.execute();
1
2
3
4
//从ADF Tree 或者 Table中获取数据
DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
FacesCtrlHierBinding treeData = (FacesCtrlHierBinding)bc.getControlBinding(”tree”);
Row[] rows = treeData.getAllRowsInRange();
1
2
3
4
5
6
7
//从iterator 的当前行获取一个 attribute的值
DCIteratorBinding iterBind= (DCIteratorBinding)dcBindings.get(”testIterator”);
String attribute = (String)iterBind.getCurrentRow().getAttribute(”field1″);
<code>
<code lang="java">
// 获取错误
String error = iterBind.getError().getMessage();
1
2
3
4
//刷新iterator
bindings.refreshControl();
iterBind.executeQuery();
iterBind.refresh(DCIteratorBinding.RANGESIZE_UNLIMITED);
1
2
3
4
5
6
// 获取 iterator的所有行
Row[] rows = iterBind.getAllRowsInRange();
TestData dataRow = null;
for (Row row : rows) {
dataRow = (TestData)((DCDataRow)row).getDataProvider();
}
1
2
3
4
5
//获取iterator当前行的另一种方法
FacesContext ctx = FacesContext.getCurrentInstance();
ExpressionFactory ef = ctx.getApplication().getExpressionFactory();
ValueExpression ve = ef.createValueExpression(ctx.getELContext(), “#{bindings.testIter.currentRow.dataProvider}”, TestHead.class);
TestHead test = (TestHead)ve.getValue(ctx.getELContext());
1
2
3
4
5
// 获得一个on bean
FacesContext ctx = FacesContext.getCurrentInstance();
ExpressionFactory ef = ctx.getApplication().getExpressionFactory();
ValueExpression ve = ef.createValueExpression(ctx.getELContext(), “#{testSessionBean}”, TestSession.class);
TestSession test = (TestSession)ve.getValue(ctx.getELContext());
1
2
3
4
5
6
7
8
9
//获取askflow的Binding
DCTaskFlowBinding tf = (DCTaskFlowBinding)dc.findExecutableBinding(”dynamicRegion1″);
<code>
<code lang="java">
//获取异常并显示到页面
catch(Exception e) {
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), “”);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//重置控件的所有子控件
private void resetValueInputItems(AdfFacesContext adfFacesContext,
UIComponent component){
List items = component.getChildren();
for ( UIComponent item : items ) {
resetValueInputItems(adfFacesContext,item);
if ( item instanceof RichInputText  ) {
RichInputText input = (RichInputText)item;
if ( !input.isDisabled() ) {
input.resetValue() ;
adfFacesContext.addPartialTarget(input);
};
} else if ( item instanceof RichInputDate ) {
RichInputDate input = (RichInputDate)item;
if ( !input.isDisabled() ) {
input.resetValue() ;
adfFacesContext.addPartialTarget(input);
};
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//重定向到另一个URL
ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)ectx.getResponse();
String url = ectx.getRequestContextPath()+/adfAuthentication?logout=true&amp;end_url=/faces/start.jspx;
try {
response.sendRedirect(url);
} catch (Exception ex) {
ex.printStackTrace();
}
<code lang="java">
// 刷新控件(PPR)
AdfFacesContext.getCurrentInstance().addPartialTarget(UIComponent);
// 查找控件
private UIComponent getUIComponent(String name) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
return facesCtx.getViewRoot().findComponent(name) ;
}
1
2
3
4
5
6
7
8
9
10
11
//获取 bc application module
private OEServiceImpl getAm(){
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, “#{data.OEServiceDataControl.dataProvider}”,
Object.class);
return   (OEServiceImpl)valueExp.getValue(elContext);
}
1
2
3
4
5
6
7
//获取table选中的行
RowKeySet selection = resultTable.getSelectedRowKeys();
Object[] keys = selection.toArray();
List receivers = new ArrayList(keys.length);
for ( Object key : keys ) {
User user = modelFriends.get((Integer)key);
}
1
2
3
4
5
6
7
8
// 获取table选中的行的另一种
for (Object facesRowKey : table.getSelectedRowKeys()) {
table.setRowKey(facesRowKey);
Object o = table.getRowData();
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
Row row = rowData.getRow();
Test testRow = (Test)((DCDataRow)row).getDataProvider() ;
}

原创粉丝点击