Spring mvc interceptor addObject?

My suspicion is that the controller has returned a redirect view. When you add attributes to the model used by RedirectView Spring will tack the attributes on to the URL.

Up vote 1 down vote favorite share g+ share fb share tw.

I have an interceptor which extends the HandlerInterceptorAdapter. When I add an object to my ModelAndView it also gets added to my url as a path variable but I don't want that. @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (null == modelAndView) { return; } log.

Info("Language in postHandle: {}", LocaleContextHolder.getLocale()); modelAndView. AddObject("selectedLocale", LocaleContextHolder.getLocale()); } When I add something to my ModelAndView in the controller itself, it doesn't appear in the url. Spring-mvc interceptor link|improve this question edited Mar 20 at 11:42skaffman114k8136227 asked Mar 20 at 11:37Willem Van Pelt63 0% accept rate.

I was wrong...I meant HandlerInterceptorAdapter – Willem Van Pelt Mar 20 at 11:42.

My suspicion is that the controller has returned a redirect view. When you add attributes to the model used by RedirectView, Spring will tack the attributes on to the URL. Try looking inside the ModelAndView object to see if the view is a RedirectView, and if so, then don't add the locale attribute.

– Willem Van Pelt Mar 20 at 11:43 I just told you how. – skaffman Mar 20 at 11:43 But I need the locale attribute? I use to give a different css style in my language menu option for the currently used language – Willem Van Pelt Mar 20 at 11:46 @Villem: You're not understanding me.

Only add the attribute if the view is not a RedirectView. Forwarding to a JSP is not a redirect, and that's where you need the attribute. – skaffman Mar 20 at 13:52 See my post below this the code AS-IS but I still have the same issue... – Willem Van Pelt Mar 207 at 13:25.

I have edited the code and added a check if the is a RedirectView. If not than I will add the additional model objects. @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) { if (null == modelAndView) { return; } log.

Info("Language in postHandle: {}", LocaleContextHolder.getLocale()); if(!(modelAndView.getView() instanceof RedirectView)) { addAdditionalModelObjects(request, modelAndView); } }.

I used setAttribute on the request instead to get around this problem request. SetAttribute("jsFiles", children).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions