Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces - How to redirect to mobile version?

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?

like image 517
Ygor Fonseca Avatar asked May 29 '12 23:05

Ygor Fonseca


2 Answers

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.

like image 174
BalusC Avatar answered Sep 29 '22 10:09

BalusC


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/

like image 21
chadpeppers Avatar answered Sep 29 '22 10:09

chadpeppers