Results 1 to 6 of 6

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

  1. #1
    Join Date
    Feb 2013
    Posts
    2

    Default 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 www.website.com/mobile//. What is the best way to ignore redirect requests in the LiteDeviceDelegatingViewResolver?

    controller code
    Code:
    //display the dashboard if everything goes smoothly
    			return new ModelAndView("redirect:/");
    resolver code
    Code:
    <beans:bean class="org.springframework.mobile.device.view.LiteDeviceDelegatingViewResolver">
            <beans:constructor-arg>
                <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:bean>
            </beans:constructor-arg>
            <beans:property name="enableFallback" value="true" />
            <beans:property name="mobilePrefix" value="mobile/" />
            <beans:property name="tabletPrefix" value="tablet/" />
        </beans:bean>
    BTW, love the product, works great!

  2. #2
    Join Date
    Nov 2010
    Posts
    175

    Default

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

    https://jira.springsource.org/browse/MOBILE-63

    thanks for the feedback!
    Roy Clarkson
    Spring Mobile Projects Lead

  3. #3
    Join Date
    Nov 2010
    Posts
    175

    Default

    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!
    Roy Clarkson
    Spring Mobile Projects Lead

  4. #4
    Join Date
    Feb 2013
    Posts
    2

    Default

    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 www.website.com/context/thanks/, 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 www.website.com/context/mobile/thanks/ does not exist. Also in the redirect: command you can specify and absolute url, like 'redirect:http://www.google.com/'. I just tested this, and it will take you to: 'www.website.com/context/mobile/http://www.google.com/'.

    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.

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

  5. #5
    Join Date
    Nov 2010
    Posts
    175

    Default

    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.
    Roy Clarkson
    Spring Mobile Projects Lead

  6. #6
    Join Date
    Nov 2010
    Posts
    175

    Default

    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.
    Roy Clarkson
    Spring Mobile Projects Lead

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •