Search in sources :

Example 56 with ObjectError

use of org.springframework.validation.ObjectError in project opennms by OpenNMS.

the class DefaultDistributedPollerServiceTest method testPauseLocationMonitorBindingErrors.

public void testPauseLocationMonitorBindingErrors() {
    LocationMonitorIdCommand command = new LocationMonitorIdCommand();
    BindException errors = new BindException(command, "command");
    errors.addError(new ObjectError("foo", null, null, "foo"));
    assertEquals("error count before pause", 1, errors.getErrorCount());
    replayMocks();
    m_distributedPollerService.pauseLocationMonitor(command, errors);
    verifyMocks();
    assertEquals("error count after pause", 1, errors.getErrorCount());
}
Also used : LocationMonitorIdCommand(org.opennms.web.svclayer.model.LocationMonitorIdCommand) ObjectError(org.springframework.validation.ObjectError) BindException(org.springframework.validation.BindException)

Example 57 with ObjectError

use of org.springframework.validation.ObjectError in project FS-Blog by JamesZBL.

the class UserController method fFrontUserLogin.

/**
 * 前台用户登录
 * 表单提交
 */
@PostMapping("/userlogin.f")
public String fFrontUserLogin(HttpServletRequest request, Model model, @Valid UserLoginForm loginForm, BindingResult bindingResult) throws Exception {
    if (bindingResult.hasErrors()) {
        List<ObjectError> errors = bindingResult.getAllErrors();
        addModelAtt(model, VIEW_MSG, errors.get(0).getDefaultMessage());
        return "userlogin";
    }
    User user = mUserService.loginAuthentication(loginForm);
    if (null != user) {
        mUserService.joinSession(request, user);
        return "redirect:/";
    }
    addModelAtt(model, VIEW_MSG, "用户名或密码错误");
    return "userlogin";
}
Also used : ObjectError(org.springframework.validation.ObjectError) User(me.zbl.fullstack.entity.User) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

ObjectError (org.springframework.validation.ObjectError)57 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 BindException (org.springframework.validation.BindException)10 FieldError (org.springframework.validation.FieldError)8 BusinessRuleException (org.mifos.service.BusinessRuleException)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 BindingResult (org.springframework.validation.BindingResult)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)5 Test (org.junit.Test)5 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)5 LocationMonitorIdCommand (org.opennms.web.svclayer.model.LocationMonitorIdCommand)5 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)5 MapBindingResult (org.springframework.validation.MapBindingResult)5 Document (org.w3c.dom.Document)5 Element (org.w3c.dom.Element)5 ArrayList (java.util.ArrayList)3 Errors (org.springframework.validation.Errors)3 MethodArgumentNotValidException (org.springframework.web.bind.MethodArgumentNotValidException)3 ServletException (javax.servlet.ServletException)2