Example usage for org.springframework.validation BindException rejectValue

List of usage examples for org.springframework.validation BindException rejectValue

Introduction

In this page you can find the example usage for org.springframework.validation BindException rejectValue.

Prototype

@Override
    public void rejectValue(@Nullable String field, String errorCode) 

Source Link

Usage

From source file:org.toobsframework.exception.ValidationException.java

public ValidationException(Object bean, String name, String field, String errorCode) {
    BindException bindException = new BindException(bean, name);
    bindException.rejectValue(field, errorCode);
    this.errors.add(bindException);
}

From source file:com.hs.mail.web.controller.FetchAccountFormController.java

private void rejetMandatoryField(String field, String value, BindException errors) {
    if (StringUtils.isEmpty(value)) {
        // Mandatory field
        errors.rejectValue(field, "field.required");
    }// ww  w. j  ava  2  s.c  o  m
}

From source file:no.dusken.barweb.admin.EditVareController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object,
        BindException errors) throws Exception {
    Vare vare = (Vare) object;/*ww  w .j  a v  a2  s  .  c om*/

    if (vare.getExternalPrice() < 0 || vare.getInternalPrice() < 0) {
        errors.rejectValue("internalprice", "negativevalue");
    }

    return super.onSubmit(request, response, object, errors);
}

From source file:org.tsm.concharto.web.forgot.ResetController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {

    User user = getUser(request);//from w  w  w  . j ava2s .c o m
    if (user == null) {
        //tell the user there was a problem 
        errors.rejectValue("username", "invalidKey.resetForm.username");
        return new ModelAndView(getFormView(), errors.getModel());
    }
    //validate the password fields
    AuthForm authForm = (AuthForm) command;
    AuthFormValidatorHelper.validatePasswordFields(authForm, errors);
    if (errors.hasErrors()) {
        return new ModelAndView(getFormView(), errors.getModel());
    }

    //ok, now we can reset the password
    user.setPassword(PasswordUtil.encrypt(authForm.getPassword()));

    //and remove the key so the email can't be used again
    user.getUserNote().setPasswordRetrievalKey(null);
    userDao.save(user);
    log.info("user " + user.getUsername() + " has reset their password");

    //now log in
    sessionHelper.setUserInSession(request, user);

    return super.onSubmit(request, response, command, errors);
}

From source file:org.tsm.concharto.web.forgot.ResetController.java

@Override
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors)
        throws Exception {
    //get the user for whom this password applies
    User user = getUser(request);/*from w ww  . ja v a2 s .c  o m*/
    if (user == null) {
        //tell the user there was a problem 
        errors.rejectValue("username", "invalidKey.resetForm.username");
        return new ModelAndView(getFormView(), errors.getModel());
    }
    return super.showForm(request, response, errors);
}

From source file:com.hs.mail.web.controller.AccountFormController.java

@Override
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
        throws Exception {
    User user = (User) command;/* w w  w. j a va  2  s.  c o m*/
    String userName = RequestUtils.getParameter(request, "userName");
    if (StringUtils.isEmpty(userName)) {
        // Mandatory field
        errors.rejectValue("userName", "field.required");
    } else {
        domain = RequestUtils.getParameter(request, "domain");
        user.setUserID(new StringBuffer(userName).append("@").append(domain).toString());
    }
    if (StringUtils.isNotEmpty(user.getForwardTo())) {
        try {
            MailUtils.validateAddress(user.getForwardTo());
        } catch (ParseException e) {
            errors.rejectValue("forwardTo", "invalid.address");
        }
    }
}

From source file:com.hs.mail.web.controller.AliasFormController.java

@Override
protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors)
        throws Exception {
    Alias alias = (Alias) command;//from  w  ww .  j  a v a 2 s . c  o m
    String aliasName = RequestUtils.getParameter(request, "aliasName");
    if (StringUtils.isEmpty(aliasName)) {
        // Mandatory field
        errors.rejectValue("aliasName", "field.required");
    } else {
        domain = RequestUtils.getParameter(request, "domain");
        alias.setAlias(new StringBuffer(aliasName).append("@").append(domain).toString());
    }
    if (StringUtils.isEmpty(alias.getUserID())) {
        // Mandatory field
        errors.rejectValue("userID", "field.required");
    } else {
        User deliverTo = manager.getUserByAddress(alias.getUserID());
        if (deliverTo == null) {
            errors.rejectValue("userID", "not.exist.address");
        } else {
            alias.setDeliverTo(deliverTo.getID());
        }
    }
}

From source file:com.hs.mail.web.controller.AliasFormController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    WebSession session = new WebSession(request, response);
    try {/*from  w  w w  .  j av  a2s  . co  m*/
        doSubmitAction(session, command);
        return new ModelAndView(getSuccessView(), errors.getModel());
    } catch (DataIntegrityViolationException ex) {
        // Unique key violation
        errors.rejectValue("aliasName", "address.alreay.exist");
        return showForm(request, response, errors);
    }
}

From source file:org.tonguetied.web.ChangePasswordController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    ModelAndView mav;//from   w  w w  .j av  a  2s.com
    ChangePasswordForm form = (ChangePasswordForm) command;
    try {
        this.userService.changePassword(getCurrentUser(), form.getOldPassword(), form.getNewPassword());
        mav = new ModelAndView(getSuccessView());
    } catch (AuthenticationException ae) {
        errors.rejectValue("oldPassword", "error.invalid.password");
        mav = showForm(request, response, errors);
    }

    return mav;
}

From source file:com.hs.mail.web.controller.AccountFormController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    WebSession session = new WebSession(request, response);
    try {// ww  w  .j  a  v a 2s. c  o m
        doSubmitAction(session, command);
        return new ModelAndView(getSuccessView(), errors.getModel());
    } catch (DataIntegrityViolationException ex) {
        // Unique key violation
        errors.rejectValue("userName", "address.alreay.exist");
        return showForm(request, response, errors);
    }
}