ADF中页面导航总结

在实际项目开发中,页面的导航(navigation)规则会比较复杂。整个系统的页面浏览风格先设计好很重要,点击按钮请求新页面,是在原browser window(view port)中刷新页面,还打开新的window;某个页面可能只允许打开一个window;是否使用dynamic tab等等。本文总结几点在ADF中请求页面的方法。当然ADF框架中的控制层可以使用JSF page flow和ADF task flow,ADF task flow具有更好的可重用性和模块化。这里只描述JSF page flow,ADF task flow的操作类似。

1,使用JSF page flow中的navigation rule

  <navigation-rule>
    <from-view-id>/untitled1.jsf</from-view-id>
    <navigation-case>
      <from-outcome>toPage2</from-outcome>
      <to-view-id>/untitled2.jsf</to-view-id>
    </navigation-case>
  </navigation-rule>
1)在command button等具有Action属性的组件中使用该Rule:
 <af:commandButton text="commandButton 1" id="cb1" action="toPage2"/>

2)在Java代码中可以返回“toPage2”来控制页面的导航

public String onClick() {
    //在页面刷新前执行一些逻辑操作

    if (xxx) {
        return "toPage2";
    } else {
       return "toPage1";
    }
}

3)在没有Action属性的组件中可以进行如下操作,比如点击CheckBox,true时导航到新页面,需要设置AutoSubmit为true

    public void setSelected(boolean selected) {
        this.selected = selected;

        FacesContext fc = FacesContext.getCurrentInstance();

        if (selected) {
            fc.getApplication().getNavigationHandler().handleNavigation(fc, null, "toPage2");
        }
    }

2,使用Java代码导航到任意的页面

1)如果没在JSF page flow中定义navigation rule,可以使用下面的代码来刷新到新的页面

            FacesContext fctx = FacesContext.getCurrentInstance();
            ViewHandler vh = fctx.getApplication().getViewHandler();
            UIViewRoot viewToRender = vh.createView(fctx, "/untitled2.jsf");
            fctx.setViewRoot(viewToRender);
            fctx.renderResponse();

3,在新窗口(window)中打开页面的方法

1)使用af: goLink,destination指定为目标页面File Name,targetFrame为_blank

<af:goLink text="goLink 1" id="gl1" targetFrame="_blank" destination="untitled2.jsf"/>
2)使用redirect

可以参考我以前的文章:ADF页面重定向

3)这里提到的1)和2)两种方法,可以指向外部地址,做为一个连接到外站的方法


2011/12/17  卢玉双 @上海


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值