本文整理汇总了Java中org.springframework.validation.BindException.reject方法的典型用法代码示例。如果您正苦于以下问题:Java BindException.reject方法的具体用法?Java BindException.reject怎么用?Java BindException.reject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.BindException
的用法示例。
在下文中一共展示了BindException.reject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modelAndView
import org.springframework.validation.BindException; //导入方法依赖的package包/类
@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());
}
示例2: handleOnSubmit
import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @throws Exception
* @see com.communote.server.web.commons.controller.BaseFormController#handleOnSubmit(javax.servlet
* .http.HttpServletRequest, javax.servlet.http.HttpServletResponse, Object,
* org.springframework.validation.BindException)
*/
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
Object command, BindException errors) throws Exception {
InviteUserForm form = (InviteUserForm) command;
validateForm(form, errors);
boolean success = false;
if (errors.getErrorCount() == 0) {
try {
UserVO userToInvite = getUserToInvite(form);
if (userToInvite != null) {
userToInvite.setRoles(new UserRole[] { UserRole.ROLE_KENMEI_USER });
if (userToInvite.getLanguage() == null) {
userToInvite.setLanguage(getUserLocaleWithFallback(form));
}
success = inviteUser(request, response, form, errors, userToInvite);
} else {
// well it only can be an external user
String field = getExternalUsernameErrorField(getErrorFields(form
.getInvitationProvider()));
if (field == null) {
field = getAliasErrorField(getErrorFields(form.getInvitationProvider()));
}
errors.rejectValue(field, "error.external.user.not.found",
"The external user does not exist!");
}
} catch (DataAccessException e) {
LOG.warn(e.getMessage());
MessageHelper.saveErrorMessageFromKey(request, "error.external.system.down");
errors.reject("error.external.system.down");
}
if (success) {
ControllerHelper.setApplicationSuccess(response);
} else {
ControllerHelper.setApplicationFailure(response);
}
}
request.setAttribute("anErrorOccured", errors.getErrorCount() != 0);
return getModelAndView(request, response, command, errors);
}
示例3: doUpdateProfile
import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
* Update a user profile
*
* @param request
* the request
* @param response
* the response
* @param userId
* the ID of the user whose profile will be updated
* @param form
* the form backing object
* @param errors
* object to bind errors
* @return the new model and view or null in case of exception
*/
private ModelAndView doUpdateProfile(final HttpServletRequest request,
final HttpServletResponse response, final UserProfileForm form, BindException errors,
final Long userId) {
if (errors.getErrorCount() != 0) {
return null;
}
try {
ServiceLocator.instance().getService(TransactionManagement.class)
.execute(new RunInTransaction() {
@Override
public void execute() throws TransactionException {
UserManagement userManagement = ServiceLocator.instance().getService(
UserManagement.class);
userManagement.updateLanguage(userId, form.getLanguageCode());
ServiceLocator.findService(UserProfileManagement.class)
.updateUserProfile(userId, form.getUserProfile());
String[] tagsAsStringArray = TagParserFactory.instance()
.getDefaultTagParser().parseTags(form.getTags());
Set<TagTO> tags = new HashSet<TagTO>();
for (String tag : tagsAsStringArray) {
tags.add(new TagTO(tag, Types.ENTITY.getDefaultTagStoreId()));
}
userManagement.updateUserTags(userId, tags);
}
});
// change the language
SessionHandler.instance().currentUserLocaleChanged(request);
String message = MessageHelper.getText(request, "user.profile.update.success");
MessageHelper.saveMessage(request, message);
ControllerHelper.setApplicationSuccess(response);
return new ModelAndView(getFormView(), getCommandName(), form);
} catch (Exception e) {
// TODO error messages is not informative
errors.reject("user.profile.update.error", "Update error");
LOGGER.error("Error updating profile: {}", e.getMessage(), e);
ControllerHelper.setApplicationFailure(response);
}
return null;
}