PDA

View Full Version : RedirectView with attributes



asears
Feb 21st, 2005, 10:43 AM
Is it possible to set attributes in one controller, and retreive the attributes in the next controller?

Controller A is extended from a SimpleFormController, and in the onSubmit(), I use the request.setAttribute("name", "value"). The return statement:

return new ModelAndView( new RedirectView(this.getSuccessView()), modelMap );

Controller B is extended from a ParameterizableViewController, and in the handleRequestInternal(), the request.getAttribute("name") returns a null.

the part of the servlet mapping xml file looks like this:


<bean id="controllerA" class="com.blah.example.controllerA">
<property name="formView">
<value>controllerA</value>
</property>
<property name="successView">
<value>controllerB</value>
</property>
<property name="sessionForm">
<value>true</value>
</property>
</bean>

<bean id="controllerB" class="com.blah.example.controllerB">
<property name="viewName">
<value>controllerB</value>
</property>
</bean>


The purpose of this is so that the parameter does not have to be displayed in the URL.

rrsIPOV
Feb 21st, 2005, 09:49 PM
The redirect view goes through the user's browser, so request scoped variables aren't going to work. If you really don't want the URL to have parameters then use session scoped attributes. Alternatively, use a querystring but add a only-once token to it to prevent user's from trying to resubmit or bookmark a dynamic page.

Kesasar
Feb 23rd, 2005, 02:21 AM
and it works



RedirectView redirection = new RedirectView&#40;getSuccessView&#40;&#41;,true&#41;;
redirection.addStaticAttribute&#40;"FOO","BAR"&#41;;
return new ModelAndView&#40;redirection&#41;;