-
Jan 25th, 2007, 12:44 PM
#1
SimpleFormController with multiple views
In struts I can have a controller process a page and determine based on input values which page to redirect. In Spring MVC I see only one success view. In struts I could have successview1, successview2, alternateview, etc.
I am able to hard code the redirect in Spring MVC this way:
if (x == 1)
{
return new ModelAndView(new RedirectView("processing.html"));
}
else
{
return new ModelAndView(new RedirectView(getSuccessView()));
}
}
but I'd rather not hard code the alternative success view in the controller, I'd rather have it in the configuration file, like struts. Is there an easy way to do this using Spring MVC with a SimpleFormController?
-
Jan 25th, 2007, 02:43 PM
#2
I never did this but I think you can declare those values in the constructor of your SimpleFormController and then declare those values in the configuration file.
-
Jan 25th, 2007, 02:59 PM
#3
Thanks Shoa. I trid adding new properties to the config file, but if it doesn't match one of the predefined names then Spring throws an error. For example, I have this for the configuration
<bean id="loginForm" class="LoginFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>login</value></property>
<property name="commandClass"><value>Profile</value></property>
<property name="validator"><ref bean="loginValidator"/></property>
<property name="formView"><value>signIn</value></property>
<property name="successView"><value>collectionForm</value></property>
</bean>
if i try an add a proptery named "alternateSuccessView" Spring throws an error
-
Jan 25th, 2007, 03:41 PM
#4
What about this:
public class MyController extends SimpleFormController{
private String alternateSuccessView;
public void setAlternateSuccessView(...)
..
public String getAlternateSuccessView()
..
}
Then you can declare alternateSuccessView in your configure file
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules