Announcement Announcement Module
No announcement yet.
Redirect after post (modified approach?) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Redirect after post (modified approach?)

    I'm quite new to the springframwork. I read the Redirect-after port thread a while ago while I was trying to write a simple spring-web based application

    I think I understood the idea, but i was struggling with the configuration setup
    (<bean name="newPersonSuccess" class="example.RedirectAfterPostView"> ...) in the spring-servlet.xml file.

    What about the following idea:
    Instead of using a view to do store and to retreive the model in/from the session use two controllers (RedirectAfterPostController and RedirectController).

    The RedirectAfterPostController stores the model/view in the session (when a post request is detected) and redirects the processing to the RedirectController (always using the same url). It extends AbstractFormController and basically provides a functionality similar to SimpleFormController. All user supplied form controllers that use the redirect after post pattern are derived from this controller.

    The RedirectController simply extracts model and view from the session and returns it. The Controller extends the AbstractController.

    The mechanism is similar to the original approach, but the configuration is (imo) simpler. A controller using the redirect after post pattern only needs to extend the RedirectAfterPostController, no additional configuration is needed.

    Are there any disadvantages compared to the original solution?

    best regards


    HTML Code:
      <bean id="redirectController" 
        	<property name="modelName"><value>TheModel</value></property>
      <bean id="redirectAfterPostController" 
        	<property name="modelName"><value>TheModel</value></property>
        	<property name="redirectUrl"><value>/</value></property>
      <!-- application spepcific controller -->
      <bean id="appFormController" 
    	<property name="formView" value="..."/>
            <property name="commandName"><value>...</value></property>
            <property name="commandClass"><value>d...</value></property>
          	<property name="bindOnNewForm"><value>true</value></property> 
            <property name="successView"><value>...</value></property>	
    public class ZetRedirectController extends AbstractController {
    	private String modelName;
    	protected ModelAndView handleRequestInternal(HttpServletRequest request,
    			HttpServletResponse arg1) throws Exception {
    		HttpSession session = request.getSession();
    		Object o = session.getAttribute(getModelName());
    		ModelAndView mv = (ModelAndView)o;
    		return mv;
    public abstract class RedirectAfterPostController extends AbstractFormController {
    	protected abstract ModelAndView onSubmit(Object cmd) throws Exception;
    	protected ModelAndView processFormSubmission(HttpServletRequest request,
    			HttpServletResponse response, Object cmd, BindException errors)
    			throws Exception {
    		// simply taken from the simple form controller
    		ModelAndView retval = null;
    		if (errors.hasErrors()) {
    			// ... (redisplay the form as implemented in the simpleFormController)
    		else {
    			ModelAndView mv =  onSubmit(cmd);
    			HttpSession session = request.getSession();
    			session.setAttribute(modelName, mv); 
    			retval = new ModelAndView();
    			retval.setView(new RedirectView(this.getRedirectUrl(), true));
    		return retval;
    public class AppFormController extends RedirectAfterPostController {
    	public ModelAndView onSubmit(Object command)
                throws Exception {
            	ModelAndView mv =  new ModelAndView(getSuccessView(), "xxx", new HashMap());
            	return mv;