zond
zond

Reputation: 1480

How to apply spring-mobile-device interceptor to welcome-file?

I,m using SpringMVC and i have different design for each device type Desktop/Tablet/Mobile

<!-- START of MOBILE -->
<mvc:annotation-driven>
    <mvc:argument-resolvers>
        <bean
            class="org.springframework.mobile.device.site.SitePreferenceWebArgumentResolver" />
        <bean class="org.springframework.mobile.device.DeviceWebArgumentResolver" />
    </mvc:argument-resolvers>
</mvc:annotation-driven>
<mvc:interceptors>
    <!-- Resolve the device which has generated the request -->
    <bean
        class="org.springframework.mobile.device.DeviceResolverHandlerInterceptor" />
    <!-- User's site preference -->
    <bean
        class="org.springframework.mobile.device.site.SitePreferenceHandlerInterceptor" />
    <!-- Redirects users to the device specific site -->
    <bean
        class="org.springframework.mobile.device.switcher.SiteSwitcherHandlerInterceptor"
        factory-method="urlPath">
        <constructor-arg value="/m" />
        <constructor-arg value="/t" />
        <constructor-arg value="/" />
    </bean>
</mvc:interceptors>
<!-- Device aware view resolving -->
<bean id="liteDeviceDelegatingViewResolver"
    class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
    <constructor-arg>
        <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".jsp" />
        </bean>
    </constructor-arg>
    <property name="mobilePrefix" value="m/" />
    <property name="tabletPrefix" value="t/" />
    <property name="normalPrefix" value="/" />
    <property name="enableFallback" value="true" />
</bean>
<!-- END of MOBILE -->

I have /m /t and / folders views in /WEB-INF/views/ folder for each device and all works fine, but this configuration not applies only to welcome page, ie I open page with phone and see desktop-version of login.jsp (/WEB_INF/views/login.jsp but not /WEB-INF/views/m/login.jsp)

<welcome-file-list>
    <welcome-file>/WEB-INF/views/login.jsp</welcome-file>
</welcome-file-list>

What I have to do to change to fix it.

Upvotes: 1

Views: 880

Answers (1)

nsfreak
nsfreak

Reputation: 186

Just don't specify page... and handle 'home' request by controller :)

modify your web.xml to:

<welcome-file-list>
    <welcome-file></welcome-file>
</welcome-file-list>

or just remove tag

now, your HomeController should look like this:

@Controller
public class HomeController {

@RequestMapping("/")
public String home(SitePreference sitePreference, Model model) {
    return "login";

    }
}

hope this helps.

Upvotes: 1

Related Questions