<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    soufan

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      22 隨筆 :: 0 文章 :: 0 評論 :: 0 Trackbacks

    (轉) Filter和Servlet中如何訪問FacesContext?

    ?

    在?Faces realm外,例如 在 ?filter 或者servlet中,當 FacesContent.getCurrentInstance() 返回null時候,你可以使用FacesContextFactory來得到FacesContext,下面是一個示例.


    //?You?need?an?inner?class?to?be?able?to?call?FacesContext.setCurrentInstance
    //?since?it's?a?protected?method
    private?abstract?static?class?InnerFacesContext?extends?FacesContext
    {
    ??protected?static?void?setFacesContextAsCurrentInstance(FacesContext?facesContext)?{
    ????FacesContext.setCurrentInstance(facesContext);
    ??}
    }

    private?FacesContext?getFacesContext(ServletRequest?request,?ServletResponse?response)?{
    ??//?Try?to?get?it?first
    ??FacesContext?facesContext?=?FacesContext.getCurrentInstance();
    ??if?(facesContext?!=?null)?return?facesContext;

    ??FacesContextFactory?contextFactory?=?(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    ??LifecycleFactory?lifecycleFactory?=?(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    ??Lifecycle?lifecycle?=?lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

    ??//?Either?set?a?private?member?servletContext?=?filterConfig.getServletContext();
    ??//?in?you?filter?init()?method?or?set?it?here?like?this:
    ??//?ServletContext?servletContext?=?((HttpServletRequest)request).getSession().getServletContext();
    ??//?Note?that?the?above?line?would?fail?if?you?are?using?any?other?protocol?than?http

    ??//?Doesn't?set?this?instance?as?the?current?instance?of?FacesContext.getCurrentInstance
    ??facesContext?=?contextFactory.getFacesContext(servletContext,?request,?response,?lifecycle);

    ??//?Set?using?our?inner?class
    ??InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);

    ??//?set?a?new?viewRoot,?otherwise?context.getViewRoot?returns?null
    ??UIViewRoot?view?=?facesContext.getApplication().getViewHandler().createView(facesContext,?"yourOwnID");
    facesContext.setViewRoot(view);

    ??return?facesContext;
    }
    posted on 2006-12-19 15:52 soufan 閱讀(425) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 中文字幕久久亚洲一区| 免费国产真实迷j在线观看| 亚洲毛片αv无线播放一区| 日韩在线观看视频免费| 免费jjzz在在线播放国产| 噜噜噜亚洲色成人网站| 免费国产在线观看老王影院| 国产亚洲视频在线观看网址| 国产美女做a免费视频软件| 日日摸日日碰夜夜爽亚洲| 全部免费a级毛片| eeuss影院免费直达入口| 国产午夜亚洲精品理论片不卡 | 99视频在线看观免费| 亚洲免费在线播放| 久久九九兔免费精品6| 亚洲一区二区三区无码国产| 女人18特级一级毛片免费视频 | www成人免费视频| 亚洲自偷自偷偷色无码中文| 免费国产成人18在线观看| 亚洲综合在线视频| 91在线视频免费91| 美女免费视频一区二区三区| 国产午夜亚洲精品午夜鲁丝片 | 国产午夜亚洲精品不卡免下载| 亚洲A∨午夜成人片精品网站| 岛国精品一区免费视频在线观看 | 国产国产人免费人成成免视频| 久久久久亚洲AV成人无码网站| 噼里啪啦免费观看高清动漫4| 亚洲1区2区3区精华液| 亚洲日韩欧洲乱码AV夜夜摸| 亚洲黄色免费网站| 成人亚洲国产精品久久| 国产精品亚洲精品日韩已满| 成人性生交大片免费看无遮挡| 一区二区三区在线免费观看视频| 亚洲男人天堂av| 亚洲精品成人a在线观看| 99re视频精品全部免费|