當前位置: 首頁>>代碼示例>>Java>>正文


Java BindException.getErrorCount方法代碼示例

本文整理匯總了Java中org.springframework.validation.BindException.getErrorCount方法的典型用法代碼示例。如果您正苦於以下問題:Java BindException.getErrorCount方法的具體用法?Java BindException.getErrorCount怎麽用?Java BindException.getErrorCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.validation.BindException的用法示例。


在下文中一共展示了BindException.getErrorCount方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleOnSubmit

import org.springframework.validation.BindException; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    Long userId = SecurityHelper.assertCurrentUserId();

    UserProfileChangeEmailForm form = (UserProfileChangeEmailForm) command;

    ModelAndView mav = null;

    if (userId != null) {
        mav = doConfigUser(request, response, form, userId, errors);
    }

    if (errors.getErrorCount() > 0 || mav == null) {
        mav = showForm(request, errors, getFormView());
    }

    return mav;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:23,代碼來源:UserProfileChangeEmailController.java

示例2: 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

示例3: handleOnSubmit

import org.springframework.validation.BindException; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    UserProfileForm form = (UserProfileForm) command;
    ModelAndView mav = null;
    Long userId = SecurityHelper.getCurrentUserId();
    if (userId != null) {
        mav = doUpdateProfile(request, response, form, errors, userId);
    }
    if (errors.getErrorCount() > 0 || mav == null) {
        mav = showForm(request, errors, getFormView());
    }
    return mav;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:18,代碼來源:UserProfileDetailsController.java

示例4: handleOnSubmit

import org.springframework.validation.BindException; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {

    ModelAndView mav = handelAction(request, response, errors, command);

    if (mav == null || errors.getErrorCount() > 0) {
        mav = showForm(request, errors, getFormView());
    }

    return mav;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:16,代碼來源:ClientProfileController.java

示例5: getModelAndView

import org.springframework.validation.BindException; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView getModelAndView(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors) throws Exception {
    if (errors.getErrorCount() > 0) {
        return showForm(request, errors, getFormView());
    }
    MessageHelper.saveMessage(request,
            ResourceBundleManager.instance().getText("client.invitation.email.send.succesful",
                    SessionHandler.instance().getCurrentLocale(request)));
    return ControllerHelper.replaceModuleInMAV(new ModelAndView(getSuccessView(), "command",
            formBackingObject(request)));
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:16,代碼來源:InviteUserToClientController.java

示例6: 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

示例7: handleOnSubmit

import org.springframework.validation.BindException; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    ModelAndView mav;
    Long currentUserId = SecurityHelper.assertCurrentUserId();
    Blog blog;
    BlogManagementForm form = (BlogManagementForm) command;
    if (StringUtils.equals(form.getAction(), FormAction.CREATE) && form.getBlogId() == null) {
        blog = createTopic(createTopicTO(currentUserId, form), request, errors);
    } else if (StringUtils.equals(form.getAction(), FormAction.EDIT)
            && form.getBlogId() != null) {
        blog = updateTopic(form.getBlogId(), createTopicTO(currentUserId, form), request,
                errors);
    } else {
        throw new RuntimeException("invalid formular state");
    }
    if (blog != null) {
        updateForm(form, blog);
    }
    if (errors.getErrorCount() > 0 || blog == null) {
        ControllerHelper.setApplicationFailure(response);
        mav = showForm(request, errors, getFormView());
    } else {
        ControllerHelper.setApplicationSuccess(response);
        mav = new ModelAndView(this.getFormView(), getCommandName(), form);
    }
    return mav;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:32,代碼來源:BlogManagementController.java

示例8: 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;
}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:59,代碼來源:UserProfileDetailsController.java


注:本文中的org.springframework.validation.BindException.getErrorCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。