Results 1 to 6 of 6

Thread: Can not reach onSubmit Method

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    Default Can not reach onSubmit Method

    Hello,

    I am new to Spring and are having some odd issues. For some reason I am unable to reach onSubmit method in my controller.

    Here is my bean definition.

    Code:
        <bean name="/login.html" class="com.blah.my.webapp.LoginController">
            <property name="formView" value="/WEB-INF/jsp/login"/>
    <!--set up to go back to the form for now. Will change later-->
            <property name="successView" value="/WEB-INF/jsp/login"/> 
        </bean>
    Here is my class to save some space I have omitted imports.

    Code:
    public class LoginController extends SimpleFormController {
        
        private final Log log = LogFactory.getLog(LoginController.class);
    
    public LoginController(){
        setCommandClass(SecurityUser.class);
        setCommandName("loginUser");
    }
        
    public ModelAndView onSubmit(
                HttpServletRequest request,
                HttpServletResponse response,
                Object command,
                BindException errors) throws Exception {       
            System.out.println("reached onSubmit...............................");
            SecurityUser loginUser=(SecurityUser)command;
            List<SecurityUser> userList=new ArrayList<SecurityUser>() ;
            userList=new UserService().listAllUsers();
            ModelAndView mov = new ModelAndView(getFormView(),"loginUser",loginUser);
            if (!userList.isEmpty()){
                mov.setViewName(getSuccessView());
            }
            mov.setViewName(getFormView());
    
            return mov;
        }
    
     public ModelAndView processFormSubmission(
                HttpServletRequest request,
                HttpServletResponse response,
                Object command,
                BindException errors)
                throws Exception {
    
                
                Map model = new HashMap();
                model.put(getCommandName(), command);
                System.out.println("reached processFormSubmission...............................");
                
                return  super.processFormSubmission(request, response, command, null);
            
        }   
    }
    Beats me what I am doing wrong here. Your help is appreciated.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Don't override processFormSubmission next to that if you override then do it correctly (you are throwing away the errors)...

    Also don't put the command in the model it is already there...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Mar 2012
    Posts
    3

    Default

    Ok, I won't override processFormSubmission but I still don't understand why onSubmit is not reachable.

    Thanks

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    As I stated

    next to that if you override then do it correctly (you are throwing away the errors)...
    You are breaking things yourself, the errors are needed by the actual implementation but you simply throw them away resulting in errors.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Mar 2012
    Posts
    3

    Default

    Alright, so I turfed processFormSubmission method. Now my class looks like this.

    Code:
    public class LoginController extends SimpleFormController {
        
    private String formView;
    private String successView;
        
        private final Log log = LogFactory.getLog(LoginController.class);
    
    public LoginController(){
        setCommandClass(SecurityUser.class);
        setCommandName("loginUser");
    }
        
    public ModelAndView onSubmit(
                HttpServletRequest request,
                HttpServletResponse response,
                Object command,
                BindException errors) throws Exception {       
            System.out.println("reached onSubmit...............................");
            SecurityUser loginUser=(SecurityUser)command;
            List<SecurityUser> userList=new ArrayList<SecurityUser>() ;
            userList=new UserService().listAllUsers();
            ModelAndView mov = new ModelAndView(getFormView(),"loginUser",loginUser);
            if (!userList.isEmpty()){
                mov.setViewName(getSuccessView());
            }
            mov.setViewName(getFormView());
    
            return mov;
        }
        
    }
    However I still can't get to the onSubmit method and no exception is thrown.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Is your bean registered, do you submit your form to the correct URL is it a POST request and not a GET request... Judging from your configuration you are using the bean name as a URL is the BeanNameHandlerMapping registered and not another HandlerMapping...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •