Results 1 to 4 of 4

Thread: SimpleFormController with multiple views

  1. #1
    Join Date
    Jan 2007
    Posts
    2

    Question 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?

  2. #2
    Join Date
    Apr 2006
    Posts
    166

    Default

    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.

  3. #3
    Join Date
    Jan 2007
    Posts
    2

    Default

    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

  4. #4
    Join Date
    Apr 2006
    Posts
    166

    Default

    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
  •