Announcement Announcement Module
Collapse
No announcement yet.
onSubmit doesn't effect on second request Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • onSubmit doesn't effect on second request

    Hi all,
    I'm tryin' to prevent dublicate entry. username on db is unique. When i use
    Code:
     catch (DatabaseIntegrityViolationException e)
    block i get the dublicate entry message in the form. But when i try to submit with or without changing the value it gives NullPointerException. When i change the code block to
    Code:
    catch (UserExistsException e)
    this time i get DatabaseIntegrityViolationException on the page. The code has written according to Appfuse Spring Impl.

    Do you have any ideas about how to show the same error message till changes the value and let the manager save user ?

    Cheers
    HaLLoWeD

    Code:
        public ModelAndView onSubmit(HttpServletRequest request,
                                     HttpServletResponse response, Object command,
                                     BindException errors)
        throws Exception {
            User user = (User) command;
            Locale locale = request.getLocale();
                try {
                    mgr.saveUser(user);
    //            } catch (DatabaseIntegrityViolationException e) {
                } catch (UserExistsException e) {
                    log.warn(e.getMessage());
    
                    errors.rejectValue("username", "errors.existing.user",
                                       new Object[] {
                                           user.getUsername(), user.getEmail()
                                       }, "duplicate user");
    
                    return showForm(request, response, errors);
                }
            return new ModelAndView(getSuccessView());
    }
    [/code]
Working...
X