PDA

View Full Version : RedirectView not utilizing urlmappings (New to Spring)


jgoodwin
Feb 8th, 2006, 05:29 PM
I am developing a simple Spring MVC application that consists of 2 simpleFormControllers. I basically need to request the 2nd simpleformcontroller from within the onSubmit of the first. I am doing so with the following code.

SubmitUserIdentificationController Code:
onSubmit{
return new ModelAndView(new RedirectView(getSuccessView(),true),
"model", model);


The springapp-servlet.xml file has the following config:

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/savequestions.htm">saveSecurityQuestionsForm</prop>
<prop key="/resetpwd.htm">userValidationForm</prop>
</props>
</property>
</bean>

<bean id="UserValidationRequestValidator" class="albany.edu.pwdmaint.controllers.validators.UserVal idationRequestValidator"/>
<bean id="userValidationForm" class="albany.edu.pwdmaint.controllers.SubmitUserIdentifi cationController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>userValidationRequest</value></property>
<property name="commandClass"><value>albany.edu.pwdmaint.model.UserValidationRequest</value></property>
<property name="validator"><ref bean="UserValidationRequestValidator"/></property>
<property name="formView"><value>resetpwd</value></property>
<property name="successView"><value>savequestions.htm</value></property>
<property name="dataAccessService" ref="dao"/>
</bean>

<bean id="saveSecurityQuestionsForm" class="albany.edu.pwdmaint.controllers.SubmitSecurityQues tionsController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>saveSecurityQuestionsRequest</value></property>
<property name="commandClass"><value>albany.edu.pwdmaint.model.SaveSecurityQuestionsReq uest</value></property>
<property name="formView"><value>saveSecurityQuestions</value></property>
<property name="successView"><value>resetpasswords</value></property>
<property name="dataAccessService" ref="dao"/>
</bean>

When the redirect occurs I receive a 404 stating that savequestions.htm.jsp does not exist. Shouldn't the redirect be mapped to the saveSecurityQuestionsForm? I am not sure what I have done wrong. My web.xml maps all *.htm requests to the Spring ServletDispatcher. Any help would be greatly appreciated.

Steve O
Feb 9th, 2006, 12:03 AM
Hi,

Are you using a views.properties file? Try to remove the '.htm' from your successView... it is looking for

/WEB-INF/views/savequestions.htm.jsp

Is the "resetpasswords" (/resetpwd.htm?) working for your successView in your saveSecurityQuestionsForm?

Good luck,

Steve

jgoodwin
Feb 9th, 2006, 10:41 AM
Hi Steve,

I appreciate your help with this. I am not using a views.properties file. My intention was to have the SubmitUserIdentificationController Code:

onSubmit{
return new ModelAndView(new RedirectView(getSuccessView(),true),
"model", model);

redirect to /savequestions.htm which would be picked up by the urlmappings below. I was assuming it would then redirect to saveSecurityQuestionsForm.


<bean id="urlMapping"
class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/savequestions.htm">saveSecurityQuestionsForm</prop>
<prop key="/resetpwd.htm">userValidationForm</prop>
</props>
</property>
</bean>


I am confused obviously.

dhewitt
Feb 9th, 2006, 11:21 AM
Simple question - are you sure your RedirectView code is actually being called? Have you overridden the correct onSubmit method? It looks to me like the default behaviour is occurring, and the successView is being treated as a logical view name - which of course doesn't map to any actual jsp.

Quick sanity check - try using the shorthand for redirect views by changing your successview to :

redirect:/savequestions.htm

This logical view name should be automatically handled as a redirect by the InternalResourceViewResolver.

jgoodwin
Feb 9th, 2006, 11:45 AM
Thanks for the simple question. I need to perfrom more test, but I believe that I have overriden the wrong onSubmit method. Thanks for the help on this. I will let you know how my testing turns out.

jgoodwin
Feb 9th, 2006, 02:07 PM
Steve,

Thanks for the help. It turns out that I was utilizing the wrong onSubmit method. I really appreciate the assistance.

Thanks,
Jeff