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

  • Redirect question

    I know, there is an abundance of questions cencerning the redirct problem area, but..

    After submitting a form, a Controller implementation returns 'successView'
    So far so good. But I need to include a string with a message to be displayed first thing in this success view.

    But; my 'successView' also is a redirect one, which seem to cause this string so carefully sent in the Model object.

    How do one solve this?

    RedirectView, and in that case; could you give an example of code?


  • #2

    "But; my 'successView' also is a redirect one, which seem to cause this string so carefully sent in the Model object. disappear"


    • #3
      If you're using a redirect, any information you want to send to the view has to be included as a request parameter.


      • #4
        From the JavaDoc:

        "View that redirects to an internal or external URL, exposing all model attributes as HTTP query parameters."

        I would assume then you could obtain this string using request.getParameter("strSuccess") or whatever you called it in your model. Although this would assume you are using JSPs for a view, if not, you will have to consult your view documentation on how to obtain parameters from the query string.

        Also, an alternative would be to place the string in the session object, depending on what your session requirements are.


        • #5
          OK, thanks.

          Problem is I'm terminating the HttpSession before rendering the view. Would like to place the string to be displayed in the request.

          I understand that RedirectView has methods for adding parameters to the request. Is this correct?


          • #6
            Have I got it right?

            The code

            RedirectView view = new RedirectView("/welcome.htm", true);
            		Map map = new HashMap();
            		map.put("nextMsg","Avvikelsen har sparats");
            		resultView = new ModelAndView(view, errors.getModel());
            		return resultView;
            results in a redirection to

            /<whatevercontext>/welcome.htm?nextMsg=Avvikelsen har sparats


            The it should be possible to retrieve with JSTL like this

            <c&#58;if test="$&#123;not empty requestScope.nextMsg&#125;">
            	onLoad="javascript&#58; modalDialog&#40;$&#123;requestScope.nextMsg&#125;&#41;; return true;">
            I can't get it to work properly. Any ideas what I'm missing here?


            • #7
              I don't think setAttributes is correct. This method is for static parameters.

              I think you need to do something like

              RedirectView view = new RedirectView&#40;"/welcome.htm", true&#41;; 
              Map map = new HashMap&#40;&#41;; 
              map.put&#40;"nextMsg","Avvikelsen har sparats"&#41;; 
              resultView = new ModelAndView&#40;view, map&#41;;
              return resultView;