Book Image

SPRING COOKBOOK

Book Image

SPRING COOKBOOK

Overview of this book

Table of Contents (19 chapters)
Spring Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Switching to the normal view on mobiles


A mobile user gets the mobile version of the website by default, but he/she may want to access some contents displayed only on the normal version. Spring Mobile offers the SitePreference object for that purpose, which is to be used instead of the Device object used in the previous recipe.

How to do it…

Follow these steps to create links, to switch between the normal version and the mobile version of a website:

  1. In the Spring configuration class, declare a DeviceResolverHandlerInterceptor bean and a SitePreferenceHandlerInterceptor bean and register them as interceptors:

    @Bean
    public DeviceResolverHandlerInterceptor deviceResolverHandlerInterceptor() {
        return new DeviceResolverHandlerInterceptor();
    }
    
    @Bean
    public SitePreferenceHandlerInterceptor sitePreferenceHandlerInterceptor() {
        return new SitePreferenceHandlerInterceptor();
    }
    
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(deviceResolverHandlerInterceptor...