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
精彩评论