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

  • setExposeModelAttributes problem

    Hi everybody.

    I have a form which I control with SimpleFormController. On successful submit, I was using an injected 'redirect:/my/url'. Now I want to send some parameters from the controller to the success page. As I'm using redirect (avoid double submit problem), I have to send it as request parameter and access it through ${param.myParamName} in my success JSP page.

    I don't want the parameters to be visible on the URL. I discovered about (RedirectView.)setExposeModelAttributes(false), and it does what I want, I only can't use it properly:
    - I cannot call it on the ModelAndView constructed from my successView string because it did not resolved the View yet (getView() returns null)
    - when using this code:
    Code:
    	@Override
    	protected ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object cmd, BindException errors)
    			throws Exception {
    		...
    		RedirectView rv = new RedirectView(getSuccessView());
    		//rv.setExposeModelAttributes(false);
    		rv.setContextRelative(true);
    		ModelAndView mav = new ModelAndView(rv);
    		mav.addObject("myParamName", "myParamValue");
    		return mav;
    	}
    In this case, it works nice if I did not set 'expose' to false (in this case, the parameters remain visible in the URL)... whenever I set it to false, the parameters are gone from the URL, but they also are not available for the JSP anymore.

    What am I doing wrong here? How can I solve this?

    Thanks!

  • #2
    Please, can somebody help me?
    I'll post more on this if needed to solve the issue.

    Thanks!

    Comment


    • #3
      I'm still waiting for some help here.
      Anybody?

      Comment


      • #4
        Hi,

        When you use the RedirectView you are instructing your client's browser to issue a new GET request so if you need some properties to be visible on the requested page you need to append them as a query string at your redirect URL.

        However, if you absolutely don't want them to appear you can try the following:

        in your onSubmit method add a Map of your properties in the user's Session under a specific key then 'pull' this state form your session when you need it and add an Interceptor which clears that state after the View has been rendered.

        regards,
        savvas

        Comment


        • #5
          Originally posted by savvas View Post
          However, if you absolutely don't want them to appear you can try the following:

          in your onSubmit method add a Map of your properties in the user's Session under a specific key then 'pull' this state form your session when you need it and add an Interceptor which clears that state after the View has been rendered.
          That's possible and easy do be implemented, but its such a bad looking solution. This setExposeModelAttributes functionality exists and seems to provide exactly what I need, in a most elegant way... now I just want to know how to use it correctly.

          So, is there anybody that can point me what I'm doing wrong?

          Thanks!

          Comment


          • #6
            The setExposeModelAttributes is not doing what you think it does; it's literally just instructing the redirect view to avoid appending the model attributes to the URL querystring.

            I believe an enhancement for the type of behavior you seek has been implemented in 3.0 RC1 (http://jira.springframework.org/browse/SPR-1068). This is actually a feature I've been looking forward to for some time now.

            Comment


            • #7
              Hello,

              maybe Iím missing something here.... You want to issue a redirect to your client and have some state produced from your Controller present in your new request but still you donít want those parameters be appended as a query string in your redirect URL.

              How will you propagate those parameters then?

              Regards,
              Savvas

              Comment

              Working...
              X