当前位置: 首页>>代码示例>>Java>>正文


Java BindException.rejectValue方法代码示例

本文整理汇总了Java中org.springframework.validation.BindException.rejectValue方法的典型用法代码示例。如果您正苦于以下问题:Java BindException.rejectValue方法的具体用法?Java BindException.rejectValue怎么用?Java BindException.rejectValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.validation.BindException的用法示例。


在下文中一共展示了BindException.rejectValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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(HttpServletRequest request, HttpServletResponse response,
        UserProfileForm form, BindException errors, Long userId) {

    try {
        if (errors.getErrorCount() == 0) {
            SaveInTransaction inTransaction = new SaveInTransaction(userId, form);

            ServiceLocator.findService(TransactionManagement.class).execute(inTransaction);

            ModelAndView modelAndView = new ModelAndView(getFormView(), getCommandName(), form);

            if (userId == SecurityHelper.getCurrentUserId()) {
                SessionHandler.instance().currentUserLocaleChanged(request);
            }

            ControllerHelper.setApplicationSuccess(response);
            MessageHelper.saveMessageFromKey(request,
                    "client.user.management.save.profile.success");

            return modelAndView;
        }
    } catch (Exception e) {
        errors.rejectValue("globalError", "user.profile.update.error", "Update error");

        ControllerHelper.setApplicationFailure(response);
        MessageHelper.saveErrorMessageFromKey(request,
                "client.user.management.save.profile.error");

        LOG.error("Error updating profile: " + e.getMessage(), e);
    }
    return null;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:48,代码来源:UserManagementUserProfileController.java

示例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);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:48,代码来源:AbstractUserInviteController.java

示例3: validateForm

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * Validates the form and returns whether the validation succeeded, i.e. no errors where found.
 *
 * @param form
 *            the form to validate
 * @param errors
 *            for binding errors
 * @return true if no errors where found, false otherwise
 */
private boolean validateForm(GroupVO form, BindException errors) {
    if (StringUtils.isBlank(form.getName())) {
        errors.rejectValue("name", "form.field.error.note.empty",
                "The field must not be empty.");
    }
    if (ActionType.CREATE.equals(actionType) && StringUtils.isBlank(form.getAlias())) {
        errors.rejectValue("alias", "form.field.error.note.empty",
                "The field must not be empty.");
    }
    return !errors.hasErrors();
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:21,代码来源:ClientUserGroupCreateAndEditController.java

示例4: bind

import org.springframework.validation.BindException; //导入方法依赖的package包/类
@RequestMapping("/bind")
public String bind() throws Exception {
	BindException error = new BindException(this, "test");
	error.rejectValue("foo", "bar.error");
	throw error;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:BasicErrorControllerMockMvcTests.java


注:本文中的org.springframework.validation.BindException.rejectValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。