Announcement Announcement Module
Collapse
No announcement yet.
Form binding errors after redirect on form success?? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form binding errors after redirect on form success??

    I did a search and the closest thread I came up with was this:

    http://forum.springframework.org/showthread.php?p=53160

    But it didn't answer my question.

    I am trying to implement the PRG (Post/Redirect/Get) pattern. I am a bit new to web dev, so I had to look it up after being told I should use it. I guess I understand why it is necessary (desktop UIs are so much simpler).

    Anyway, earlier I blindly followed this direction and was experiencing these binding errors so I removed the redirect. Obviously I am doing it wrong.

    What I do is this:

    Code:
    <bean name="/changePasswordSuccess.htm" class="security.web.PasswordResultController">
        </bean>
         
        <bean name="/changePassword.htm"     class="security.web.ChangePasswordFormController">
            <property name="formView"        value="/security/changePassword" />
            <property name="successView"     value="redirect:/changePasswordSuccess.htm"/>
         </bean>
    Then:

    Code:
    public class PasswordResultController extends MultiActionController
    {
        public ModelAndView changePasswordSuccess(HttpServletRequest request, HttpServletResponse response) {
            return new ModelAndView("changePasswordSuccess");
        }
    }
    And then a very simple JSP with just one sentence.

    Problem is I see this in the URL:

    http://localhost:8080/changePassword...lt%3A+0+errors

    I have seen this a number of times in various redirect scenarios and asked about it here before in different contexts. I always just assumed I shouldn't use 'redirect' because I never got an answer here - but now I understand that I should use it, but I guess I am using it wrongly??

    Thanks for any help you can give me.

  • #2
    No replies?

    Does this have anything to do with the fact that I have a validator on the from?

    The full bean def (I simplified the previous one to keep it simple, but now maybe it is something besides the redirect?):

    Code:
    <bean name="/changePassword.htm"     class="security.web.ChangePasswordFormController">
            <property name="formView"        value="/security/changePassword" />
            <property name="successView"     value="redirect:/changePasswordSuccess.htm"/>
            <property name="cancelParamKey"  value="cancel"/>
            <property name="passwordService" ref="passwordService" />
            <property name="validator">
                <bean class="security.web.ChangePasswordValidator">
                    <property name="encoder"            ref="passwordEncoder"/>
                    <property name="passwordService"    ref="passwordService"/>                
                </bean>
            </property>
        </bean>
    Last edited by Developer Dude; Jan 6th, 2009, 12:35 PM.

    Comment


    • #3
      On the advice of a colleague, adding this to the first form controller (not the result controller), fixes the problem:

      Code:
      public ModelAndView onSubmit(Object command, BindException errors) throws Exception
          {
              return new ModelAndView(getSuccessView());
          }
      also:

      Subclasses can override this to provide custom submission handling that just depends on the command object. It's preferable to use either onSubmit(Object, BindException) or doSubmitAction(Object), though: Use the former when you want to build your own ModelAndView; use the latter when you want to perform an action and forward to the successView.
      http://static.springframework.org/sp...ontroller.html

      Comment


      • #4
        Actually, because I override doSubmitAction, I should do this:

        Code:
        public ModelAndView onSubmit(Object command, BindException errors) throws Exception
            {
                ModelAndView mav = super.onSubmit(command, errors);
                
                if (errors.getAllErrors().size() == 0) {
                    return new ModelAndView(getSuccessView());            
                }
                else
                    return mav;
            }
        Otherwise my doSubmitAction method doesn't get called.

        Comment

        Working...
        X