本文整理了Java中org.springframework.validation.BindException.reject()
方法的一些代码示例,展示了BindException.reject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.reject()
方法的具体详情如下:
包路径:org.springframework.validation.BindException
类名称:BindException
方法名:reject
暂无
代码示例来源:origin: spring-projects/spring-framework
@Test
public void modelAndView() throws Exception {
BindException bindException = new BindException(new Object(), "target");
bindException.reject("errorCode");
ModelAndView mav = new ModelAndView("viewName");
mav.addObject("attrName", "attrValue");
mav.addObject(BindingResult.MODEL_KEY_PREFIX + "attrName", bindException);
this.mvcResult.setMav(mav);
this.handler.handle(this.mvcResult);
assertValue("ModelAndView", "View name", "viewName");
assertValue("ModelAndView", "View", null);
assertValue("ModelAndView", "Attribute", "attrName");
assertValue("ModelAndView", "value", "attrValue");
assertValue("ModelAndView", "errors", bindException.getAllErrors());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBindExceptionSerializable() throws Exception {
SerializablePerson tb = new SerializablePerson();
tb.setName("myName");
tb.setAge(99);
BindException ex = new BindException(tb, "tb");
ex.reject("invalid", "someMessage");
ex.rejectValue("age", "invalidField", "someMessage");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ex);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
BindException ex2 = (BindException) ois.readObject();
assertTrue(ex2.hasGlobalErrors());
assertEquals("invalid", ex2.getGlobalError().getCode());
assertTrue(ex2.hasFieldErrors("age"));
assertEquals("invalidField", ex2.getFieldError("age").getCode());
assertEquals(new Integer(99), ex2.getFieldValue("age"));
ex2.rejectValue("name", "invalidField", "someMessage");
assertTrue(ex2.hasFieldErrors("name"));
assertEquals("invalidField", ex2.getFieldError("name").getCode());
assertEquals("myName", ex2.getFieldValue("name"));
}
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
errors.reject("repository.error");
代码示例来源:origin: infiniteautomation/ma-core-public
public static void reject(BindException errors, String errorCode, Object... args) {
errors.reject(errorCode, args, "???" + errorCode + "(10)???");
}
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
errors.reject("repository.error");
errors.reject("repository.query.error.evaluation");
代码示例来源:origin: infiniteautomation/ma-core-public
@RequestMapping(method=RequestMethod.GET)
public String initForm(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("login") LoginForm loginForm, BindingResult result) {
BindException errors = new BindException(result);
HttpSession session = request.getSession(false);
if (session != null) {
AuthenticationException ex = (AuthenticationException) session.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
if (ex != null) {
TranslatableMessage message;
if (ex instanceof AuthenticationRateException) {
message = messageForAuthenticationRateException((AuthenticationRateException) ex);
} else {
message = messageForAuthenticationFailedException(ex);
}
errors.reject(message.getKey(), message.getArgs(), ex.getMessage());
}
String username = (String)session.getAttribute("username");
if (username != null && !username.isEmpty()) {
loginForm.setUsername(username);
}
}
//TODO What if this is a forwarded request? There shan't be a session....
// display errors on the form or next to inputs like so
// errors.reject("translation.key", "Fall back text");
// errors.rejectValue("password", "translation.key", "Fall back text");
return "/WEB-INF/jsp/login.jsp";
}
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
errors.reject("repository.error");
errors.reject("repository.query.error.evaluation");
代码示例来源:origin: org.openrdf.sesame/sesame-http-webclient-spring
errors.reject("repository.error");
errors.reject("repository.query.error.evaluation");
内容来源于网络,如有侵权,请联系作者删除!