原文地址:http://www.demo356.com/?p=82
Bean中常用方法:
//获取binding容器
BindingContainer bindings = BindingContext. getCurrent ( ). getCurrentBindingsEntry ( ) ; |
//获取Page definitions的 attribute的值
AttributeBinding attr
=
(AttributeBinding
)bindings.
getControlBinding
(
"test"
)
;
attr.
setInputValue
(”test”
)
;
|
// 获取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 ( ) ; |
// 从ADF Tree 或者 Table中获取数据
DCBindingContainer dcBindings = (DCBindingContainer )BindingContext. getCurrent ( ). getCurrentBindingsEntry ( ) ; FacesCtrlHierBinding treeData = (FacesCtrlHierBinding )bc. getControlBinding (”tree” ) ; Row [ ] rows = treeData. getAllRowsInRange ( ) ; |
// 从iterator 的当前行获取一个 attribute的值
DCIteratorBinding iterBind = (DCIteratorBinding )dcBindings. get (”testIterator” ) ; String attribute = ( String )iterBind. getCurrentRow ( ). getAttribute (”field1″ ) ; |
// 刷新iterator
bindings. refreshControl ( ) ; iterBind. executeQuery ( ) ; iterBind. refresh (DCIteratorBinding. RANGESIZE_UNLIMITED ) ; |
// 获取 iterator的所有行
Row [ ] rows = iterBind. getAllRowsInRange ( ) ; TestData dataRow = null ; for (Row row : rows ) { dataRow = (TestData ) ( (DCDataRow )row ). getDataProvider ( ) ; } |
//获取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 ( ) ) ; |
// 获得一个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 ( ) ) ; |
//获取askflow的Binding
DCTaskFlowBinding tf = (DCTaskFlowBinding )dc. findExecutableBinding (”dynamicRegion1″ ) ; //获取异常并显示到页面 catch ( Exception e ) { FacesMessage msg = new FacesMessage (FacesMessage. SEVERITY_ERROR, e. getMessage ( ), “” ) ; FacesContext. getCurrentInstance ( ). addMessage ( null, msg ) ; } |
// 重置控件的所有子控件
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 ) ; } ; } } } |
// 重定向到另一个URL
ExternalContext ectx = FacesContext. getCurrentInstance ( ). getExternalContext ( ) ; HttpServletResponse response = (HttpServletResponse )ectx. getResponse ( ) ; String url = ectx. getRequestContextPath ( ) +” /adfAuthentication ?logout =true & ;end_url =/faces /start. jspx” ; try { response. sendRedirect (url ) ; } catch ( Exception ex ) { ex. printStackTrace ( ) ; } // 刷新控件(PPR) AdfFacesContext. getCurrentInstance ( ). addPartialTarget (UIComponent ) ; // 查找控件 private UIComponent getUIComponent ( String name ) { FacesContext facesCtx = FacesContext. getCurrentInstance ( ) ; return facesCtx. getViewRoot ( ). findComponent (name ) ; } |
//获取 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 ) ; } |
//获取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 ) ; } |
// 获取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 ( ) ; } |