Announcement Announcement Module
No announcement yet.
Device Aware View and ModelAndView("redirect:/") Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Device Aware View and ModelAndView("redirect:/")

    I have a website using spring web mvc and spring mobile. Everything works great except for when I return the ModelAndView object as a redirect (ModelAndView("redirect:/")). I am using the latest version of spring mobile which includes a view resolver that will add a prefix to the view file path. So if a mobile visitor is redirected to "/" the url will become What is the best way to ignore redirect requests in the LiteDeviceDelegatingViewResolver?

    controller code
    //display the dashboard if everything goes smoothly
    			return new ModelAndView("redirect:/");
    resolver code
    <beans:bean class="">
                <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
                    <beans:property name="prefix" value="/WEB-INF/jsp/" />
                    <beans:property name="suffix" value=".jsp" />
            <beans:property name="enableFallback" value="true" />
            <beans:property name="mobilePrefix" value="mobile/" />
            <beans:property name="tabletPrefix" value="tablet/" />
    BTW, love the product, works great!

  • #2
    Hi Jason, this appears to be a bug. I've created a JIRA to investigate it further.

    thanks for the feedback!


    • #3
      I've pushed a fix for this that will be in the latest snapshot. Please test if you can and let me know if it addresses your issue. Thanks!


      • #4
        Hi Roy, thanks for taking a look at my request. I've tested the snapshot and it appears to be working as your change intends, though the way I'm using redirect: may not be the way it is supposed to be used. For instance if I have a controller that processes a form, if the form is successful and I wish to take the user to a 'thank you' page located at, I would specify the url "redirect:/thanks" instead of a view name. Since this is an actual location and not a view file, the browser will get a 404 because does not exist. Also in the redirect: command you can specify and absolute url, like 'redirect:'. I just tested this, and it will take you to: ''.

        In the meantime I have found a workaround that will prevent the LiteDeviceDelegatingViewResolver from intercepting url redirects, the RedirectView must be used instead of the redirect: shortcut.

        return new ModelAndView(new RedirectView("/thanks/", true));
        Thanks for reading, again, loving the product so far!


        • #5
          Regarding the "thanks" page, the enableFallback option was meant to help with this, but it's assuming views. The second issue with absolute URLs is another bug. We'll have to consider how to best handle that. Again, really appreciate you jumping in on this milestone release and helping us flush out the issues.


          • #6
            I've pushed a change for the issue with absolute URLs. If the LiteDeviceDelegatingViewResolver detects an absolute URL it will not attempt to adjust it for mobile/tablet view resolution.