开发者

jsf navigation from one outcome to diff viewId

开发者 https://www.devze.com 2023-01-19 03:24 出处:网络
I need your help! I have a jsf app, which now have 2 versions - one for mobile and one for desktop browsers. The pages for desktop lie in folder /html, and for mobile - /html/mobile. I want one outcom

I need your help! I have a jsf app, which now have 2 versions - one for mobile and one for desktop browsers. The pages for desktop lie in folder /html, and for mobile - /html/mobile. I want one outcome decide what exactly pages to show - from /html or from开发者_运维知识库 /html/mobile.

I create session attribute isMobileBrowser - which indicates what browser I have.

 Boolean isMobileBrowser = (Boolean) session.getAttribute("isMobileBrowser");
  if (isMobileBrowser == null) {
 Enumeration e = req.getHeaders("user-agent");
while(e.hasMoreElements()) {
 String str = e.nextElement().toString().toLowerCase();
 if (str.indexOf("mobile") != -1) {
  isMobileBrowser = new Boolean(true);
  System.out.println("MOBILE BROWSER");
 } else {
  isMobileBrowser = new Boolean(false);
  System.out.println("STANDARD BROWSER");
 }
 session.setAttribute("isMobileBrowser", isMobileBrowser);
}

}

And now I want somethin like that:

 <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
     <from-outcome>clientadmin</from-outcome>
                    // if mobile
         <to-view-id>/html/mobile/clientadmin.jsf</to-view-id>
                      // if desktop
                      <to-view-id>/html/clientadmin.jsf</to-view-id>
      </navigation-case>
   </navigation-rule>

How I can do it better. I find out NavigationHandler, but dont understand how it works. I also try with conditions in xml - but I dont think they work (I use jsf 2.0).

Any help will be greate! Thanks!


If you are using jsf2.0 the you can use a value expression for . See ch. 2.4.2.1 in the JSF 2.0 spec.

If using Jsf1.2 then you have to Implement a custom ViewHandler. See how-to-make-jsf-navigation-rules-more-dynamic

0

精彩评论

暂无评论...
验证码 换一张
取 消