Announcement Announcement Module
Collapse
No announcement yet.
InternalResourceViewResolver and mobile views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • InternalResourceViewResolver and mobile views

    In Keith Donalds blog post about Spring Mobile (http://blog.springsource.com/2010/11...n-development/) I found this part interesting:


    Finally, a Tiles-based page layout that changes if the device is a mobile device:

    <definition name="page" templateExpression="/WEB-INF/layouts/${currentDevice.mobile ? 'mobile/' : 'standard/'}page.jsp" />

    I like to do something similar with a InternalResourceViewResolver in my mvc config xml.

    <bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver" prefix="/WEB-INF/views/" p:suffix=".jsp" />

    This because I'm not using Tiles but plain JSP's (decorated using SiteMesh).

    Can I use the expression like ${currentDevice.mobile ? 'mobile/' : 'standard/'} also in combination with a InternalResourceViewResolver.

    Bases on the currentDevice.mobile I want to render
    index.jsp (for desktop) or index.iphone.jsp or perhaps index.android.jsp.

  • #2
    Unfortunately InternalResourceViewResolver does not support view template expressions, it only allows a static prefix and suffix values to be injected. You could implement your own ViewResolver that would do this, perhaps even a special subclass or composite of InternalResourceViewResolver. ViewResolver is passed the HttpServletRequest and from the request you can obtain the currentDevice as a request attribute. You can also get at RequestAttributes via the RequestContextHolder thread local.

    Keith
    Last edited by Keith Donald; Nov 29th, 2010, 05:35 PM.

    Comment


    • #3
      Probabably a DeviceAwareInternalResourceViewResolver in Spring Mobile core would have benefit for everybody. Would be a feature request I guess.

      Comment


      • #4
        Yeah, I suggested this in a comment here: http://blog.springsource.com/2010/12...comment-181442.

        Comment

        Working...
        X