ADF backing Bean中常用的代码
发短消息
加为好友
本子 当前离线
最后登录
2011-5-18 
注册时间
2011-4-1 
阅读权限
200 
积分
126 
精华
帖子
29 
//selectedRowKeySet查当前选中树节点ID
RowKeySet rsk = (solveExpression ("#{pageFlowScope.EngHGroupTreeEditTree.selectedRowKeySet}");
        //access the iterator to loop over selected nodes
        Iterator rskIt = rsk.iterator();
        String groupId = "" ;
        while(rskIt.hasNext()){
        List nodeKey = (List) ();
        Key k = ((nodeKey.size()-1);
        groupId = k.getKeyValues()[0].toString();
      }
  PMSUtils.setSessionValue("EngHandoverGroupId", groupId);
BackingBean中动态创建组件
使用容器的 getChildren().add()方法
例如:想在 PanelGroupLayOut中增加一个InputText
RichInputText inputText = new RichInputText();
Children().add(inputText);
在进入或退出页面的时候执行代码
In some application developer need to execute some code at page load or need to execute some code when leave the page. If the developer need to execute the same code to many of pages in the application at page load (as sharing code will executed when any of the application page load) he need to follow this steps

主要分 4步:
1- In your ADF Application Make a new Managed-Bean (assume its name is PageListenerBean).
2- Write this code in the Managed bean
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;

import javax.faces.application.Application;
import t.FacesContext;

import ller.v2.lifecycle.Lifecycle;

import ller.v2.lifecycle.PagePhaseEvent;
import ller.v2.lifecycle.PagePhaseListener;

public class PageListenerBean implements PagePhaseListener{
public PageListenerBean() {
}

public void afterPhase(PagePhaseEvent pagePhaseEvent) {
}

public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
if (!isPostback()){
System.out.println("This Will Execute AT Page Load");
}
}

if (pagePhaseEvent.getPhaseId() == Lifecycle.METADATA_COMMIT_ID) {
if (!isPostback()){
System.out.println("This Will Execute When Leave The Page");
}
}

}
private boolean isPostback() {
return Boolean.TRUE.equals(resolveExpression("#{adfFacesContext.postback}"));
}
private Object resolveExpression(String expression) {
FacesContext facesContext = FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);
return valueExp.getValue(elContext);
}
}
3- For every page in your application you want to execute this code at page load or when you leave the page —> Right click on your jspx page and go to your page definition. Set the attribute ControllerClass inside your pageDefinition tag as the name of the managed bean.
4- Run your page to check the results.
调用EL表达式代码:如:#{st1}
    public void getExpressionInvoke(String El, SelectionEvent selectionEvent) {
        FacesContext fctx = CurrentInstance();
        ELContext elctx = ELContext();
        ExpressionFactory expressionFactory = null;
        expressionFactory = Application().getExpressionFactory();
        MethodExpression methodExpression = null;
        methodExpression =
                ateMethodExpression(elctx, El, Object.class,
                                                        new Class[] { Class() });
        methodExpression.invoke(elctx, new Object[] { selectionEvent });
    }
1. //获取binding容器
2. BindingContainer bindings
3.       =  Current().getCurrentBindingsEntry();
复制代码
1. //获取Page definitions attribute的值
2. AttributeBinding attr = (ControlBinding("test");
3. attr.setInputValue(test);
复制代码
1. // 获取action或者方法
2. OperationBinding method = OperationBinding("methodAction");
3. ute();
4. List errors = Errors();
5.
6. method = OperationBinding(methodAction);
7. Map paramsMap = ParamsMap();
8. paramsMap.put(param,value)  ;
9. ute();
复制代码
1. // ADF Tree 或者 Table中获取数据
2. DCBindingContainer dcBindings = (Current().getCurrentBindingsEntry();
3. FacesCtrlHierBinding treeData = (ControlBinding(tree);
4. Row[] rows = AllRowsInRange();
复制代码
1. // iterator 的当前行获取一个 attribute的值
2. DCIteratorBinding iterBind= ((testIterator);
3. String attribute = (CurrentRow().getAttribute(field1);
4. <code>
5. <code lang="java">
6. // 获取错误
7. String error = Error().getMessage();
复制代码
1. // 刷新iterator
2. freshControl();
3. uteQuery();
4. fresh(DCIteratorBinding.RANGESIZE_UNLIMITED);
复制代码
1. // 获取 iterator的所有行
2. Row[] rows = AllRowsInRange();
3. TestData dataRow = null;
4. for (Row row : rows) {
5. dataRow = (TestData)((DCDataRow)row).getDataProvider();
6. }
复制代码
1. //获取iterator当前行的另一种方法
2. FacesContext ctx = CurrentInstance();
3. ExpressionFactory ef = Application().getExpressionFactory();
4. ValueExpression ve = ef.ELContext(), #{stIter.currentRow.dataProvider}, TestHead.class);
5. TestHead test = (ELContext());
复制代码
1. // 获得一个on bean
2. FacesContext ctx = CurrentInstance();
3. ExpressionFactory ef = Application().getExpressionFactory();
4. ValueExpression ve = ef.ELContext(), #{testSessionBean}, TestSession.class);
5. TestSession test = (ELContext());
复制代码
1. //获取askflowBinding
2. DCTaskFlowBinding tf = (DCTaskFlowBinding)dc.findExecutableBinding(dynamicRegion1);
3. <code>
4. <code lang="java">
5. //获取异常并显示到页面
6. catch(Exception e) {
7. FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), “”);
8. CurrentInstance().addMessage(null, msg);
9. }
复制代码
1. // 重置控件的所有子控件
2. private void resetValueInputItems(AdfFacesContext adfFacesContext,
3. UIComponent component){
4. List items = Children();
5. for ( UIComponent item : items ) {
6. resetValueInputItems(adfFacesContext,item);
7. if ( item instanceof RichInputText  ) {
8. RichInputText input = (RichInputText)item;
9. if ( !input.isDisabled() ) {
10. setValue() ;
11. adfFacesContext.addPartialTarget(input);
12. };
13. } else if ( item instanceof RichInputDate ) {
14. RichInputDate input = (RichInputDate)item;
15. if ( !input.isDisabled() ) {
16. setValue() ;
17. adfFacesContext.addPartialTarget(input);
18. };
19. }
20. }
21. }
复制代码
1. // 重定向到另一个URL
2. ExternalContext ectx = CurrentInstance().getExternalContext();
3. HttpServletResponse response = (Response();
4. String url = RequestContextPath()+/adfAuthentication?logout=true&end_url=/faces/start.jspx;
5. try {
6. response.sendRedirect(url);
7. } catch (Exception ex) {el表达式获取session中的值
8. ex.printStackTrace();
9. }
10. <code lang="java">
11. // 刷新控件(PPR
12. CurrentInstance().addPartialTarget(UIComponent);
13. // 查控件
14. private UIComponent getUIComponent(String name) {
15. FacesContext facesCtx = CurrentInstance();
16. ViewRoot().findComponent(name) ;
17. }
复制代码
1. //获取 bc application module
2. private OEServiceImpl getAm(){
3. FacesContext fc = CurrentInstance();
4. Application app = fc.getApplication();
5. ExpressionFactory elFactory = ExpressionFactory();
6. ELContext elContext = fc.getELContext();
7. ValueExpression valueExp =
8. ateValueExpression(elContext, #{data.OEServiceDataControl.dataProvider},
9. Object.class);
10. return   (Value(elContext);
11. }
复制代码
1. //获取table选中的行
2. RowKeySet selection = SelectedRowKeys();
3. Object[] keys = Array();
4. List receivers = new ArrayList(keys.length);
5. for ( Object key : keys ) {
6. User user = ((Integer)key);
复制代码
1. // 获取table选中的行的另一种
2. for (Object facesRowKey : SelectedRowKeys()) {
3. table.setRowKey(facesRowKey);
4. Object o = RowData();
5. JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
6. Row row = Row();
7. Test testRow = (Test)((DCDataRow)row).getDataProvider() ;
8. }
复制代码

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。