I'm created a website in JSF 2 (primefaces 3.3) and now I want to create a mobile version. I have diferents views for desktop/mobile. I already create a custom viewhandler to detect mobile browsers. It seens to work fine. But what a don't understand is how to redirect the user to the mobile pages. I've searched a lot and nobody says where this step occurs. In what step should i do that? Redirect the user, and how to?
Do the browser detection job in a Filter
mapped on FacesServlet
instead of in a ViewHandler
.
It's then as easy as
if (needsRedirectToMobileURL) {
response.sendRedirect(mobileURL);
}
else {
chain.doFilter(request, response);
}
A ViewHandler
isn't intented to manipulate the request/response. It's intented to handle the JSF view for the given request.
Generally you do not want to redirect to a mobile site but instead use css media queries to determine what the browser size is and use different css for that. Here is a quick example
http://css-tricks.com/resolution-specific-stylesheets/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With