Ygor Fonseca
Ygor Fonseca

Reputation: 51

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?

Upvotes: 5

Views: 6366

Answers (2)

BalusC
BalusC

Reputation: 1109302

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.

Upvotes: 8

chadpeppers
chadpeppers

Reputation: 2057

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/

Upvotes: 3

Related Questions