-
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?
Thanks!
-
Hmm..
"But; my 'successView' also is a redirect one, which seem to cause this string so carefully sent in the Model object. disappear"
-
If you're using a redirect, any information you want to send to the view has to be included as a request parameter.
-
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.
-
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?
-
Have I got it right?
The code
Code:
RedirectView view = new RedirectView("/welcome.htm", true);
Map map = new HashMap();
map.put("nextMsg","Avvikelsen har sparats");
view.setAttributesMap(map);
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
Code:
<body
<c:if test="${not empty requestScope.nextMsg}">
onLoad="javascript: modalDialog(${requestScope.nextMsg}); return true;">
</c:if>
I can't get it to work properly. Any ideas what I'm missing here?
-
I don't think setAttributes is correct. This method is for static parameters.
I think you need to do something like
Code:
RedirectView view = new RedirectView("/welcome.htm", true);
Map map = new HashMap();
map.put("nextMsg","Avvikelsen har sparats");
map.putAll(errors.getModel());
resultView = new ModelAndView(view, map);
return resultView;