Results 1 to 6 of 6

Thread: Url navigation

  1. #1

    Default Url navigation

    Hi,

    I would like to know if there is a better way to to redirects in my Spring app.

    At the moment, for example, my change password page could lead to either the error page or the main app page. Returning a new ModelAndView object of the relevant view works but does not update the browser url.

    To get round this I use response.sendredirect():

    Code:
    ...
           response.sendRedirect(request.getContextPath()+"/secure/main.htm");
            return null;
    However, I now have to keep the url in the controller upto date with the mappings in the servlet xml file:

    Code:
    	<bean name="/secure/main.htm" class="com.ifst.web.controllers.MainPageController"/>
    Thanks

    Rakesh

  2. #2
    Join Date
    Apr 2005
    Location
    Porto Alegre, RS, Brazil
    Posts
    14

    Default

    Have you tried this?
    Code:
    return new RedirectView&#40;....

  3. #3

    Default

    Hi,

    thanks for the tip. I got it working using this:

    Code:
            RedirectView rv = new RedirectView&#40;"/secure/main.htm",true&#41;;
            return new ModelAndView&#40;rv&#41;;
    Its a bit cleaner but still has the url hard coded but i guess there's not much that can be done about that.

    Thanks for your time

    Rakesh

  4. #4

    Default

    Hi,

    as a follow on to my original question, how do i accomplish the same thing when there is also some data i wish to pass to the next view?

    This is how it currently works, an error condition in the controller looks like this:

    Code:
            &#125; catch &#40;InvalidLogonException e&#41; &#123;
                return errorPageRedirect&#40;e&#41;;
    .
    .
    .
        private ModelAndView errorPageRedirect&#40;Exception e&#41; &#123;
            logger.debug&#40;e.getMessage&#40;&#41;&#41;;
    
            ModelAndView mav = new ModelAndView&#40;"login_failure"&#41;;
            mav.addObject&#40;"reason", e.getMessage&#40;&#41;&#41;;
    
            return mav;
        &#125;
    so, like before, the browser url does not update. Can i get round this??

    Thanks

    Rakesh

  5. #5
    Join Date
    Apr 2005
    Location
    Porto Alegre, RS, Brazil
    Posts
    14

    Default

    I think you could make this way:
    Code:
            RedirectView rv = new RedirectView&#40;"/secure/main.htm",true&#41;;
    
            Map myModel = new HashMap&#40;&#41;;
            myModel.put&#40;"reason", e.getMessage&#40;&#41;&#41;;
    
            return new ModelAndView&#40;rv, "model", myModel&#41;;

  6. #6
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    From an "point on concerns" point of view, I think it is "leakage" to have your controller determine whether to forward or redirect. It is much better (in my very humble, but overly opinionated opinion) for your controller to just return a model and view based on a view name, and then the definition of that view is either redirect or forward etc.

Similar Threads

  1. JSF and WebFlow
    By bura in forum Web Flow
    Replies: 33
    Last Post: Apr 27th, 2006, 09:46 AM
  2. Record navigation
    By anieshuk in forum Web
    Replies: 1
    Last Post: Sep 5th, 2005, 07:52 AM
  3. SWF + JSF + SMVC + EAR
    By bostone in forum Web Flow
    Replies: 3
    Last Post: Jul 20th, 2005, 09:28 AM
  4. Replies: 1
    Last Post: Feb 6th, 2005, 08:02 AM
  5. Controller to Form Navigation?
    By cnelson in forum Web
    Replies: 1
    Last Post: Aug 20th, 2004, 06:18 AM

Posting Permissions

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