Announcement Announcement Module
No announcement yet.
velocity : automatically switch layout according to Device Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • velocity : automatically switch layout according to Device


    One problem that I had when using LiteDeviceDelegatingViewResolver is that it does not allow to switch layout according to device when delegating to a VelocityLayoutViewResolver.

    I wanted that only the DeviceDelegatingViewResolver to be aware of the device, and I also don't want the fallback layout to be a mobile or tablet layout.
    So I wrote my own delegatingViewResolver DeviceDelegatingLayoutVelocityViewResolver for this purpose. And I thought that some of you might be interested.

    One possible configuration would be :

       <bean class="">
                <bean class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
                    <property name="contentType" value="text/html;charset=UTF-8" />
                    <!-- This layout will be used if no layout for the current device is found, or in case of fallback-->
                    <property name="layoutUrl" value="/layout.vm" />
                    <property name="suffix" value=".vm" />
                    <property name="viewNames">
            <property name="enableFallback" value="true"/>
            <property name="mobilePrefix" value="mobile/" />
            <property name="tabletPrefix" value="tablet/" />
            <property name="normalPrefix" value="front/" />
            <property name="mobileLayoutUrl" value="/mobile_layout.vm"/>
            <property name="tableLayoutUrl" value="/tablet_layout.vm"/>

    I would like to have your feedbacks on this. Also if you have an idea of another name for it :-/. Also I have difficulties to test it (the LiteDeviceDelegatingViewResolverTest does not adapt easily to this).

  • #2
    Thanks for sharing!