Announcement Announcement Module
Collapse
No announcement yet.
Content negotiation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Content negotiation

    What is the recommended way to handle device-dependent presentations within Spring MVC?
    I now handle this by returning different ModelAndView objects for the different devices (in the relevant controllers), e.g. a ModelAndView("index-wap",..) or a ModelAndView("index-html",...). Ugly, and very limited.

    Ideally, I'd like to use a ViewResolver, but the ViewResolver interface only allows me to switch views based on locales - I'd like to switch based on (for example) the contents of (parts of) user-agents headers, or other values of the HTTPaccept headers.

    Seems to me that the current ViewResolver is a specific implementation of a more generic problem. Is there another way I'm currently missing?

  • #2
    You can write a HandlerInterceptorAdapter which is wired up by specifying an "interceptors" property for an AbstractHandlerMapping object. The interceptor can then modify the ModelAndView to for example use a different view name.

    http://opensource.atlassian.com/conf...File+Extension contains an example which uses a different view based on a URL extension. This can be easily modified to instead base the view on a HTTP header.

    Example handler mapping:

    <bean id="mapping" class="org...SimpleUrlHandlerMapping">
    <property name="interceptors">
    <list>
    <ref bean="viewSelectorInterceptor"/>
    </list>
    </property>
    <property name="mappings">
    ....
    </property>
    </bean>

    Comment

    Working...
    X