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


Java BindException.hasErrors方法代码示例

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


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

示例1: showForm

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#showForm(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, org.springframework.validation.BindException)
 */
@Override
protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response,
        BindException errors) throws Exception {
    ModelAndView result = null;

    if (errors.hasErrors()) {
        MessageHelper.saveErrorMessageFromKey(request, "form.error.hasFieldErrors");
    }

    // redirect to portal home page, if the current operation is not allowed with activated
    // external authentication
    if (isRefuseOnExternalAuthentication()
            && CommunoteRuntime.getInstance().getConfigurationManager()
                    .getClientConfigurationProperties().isExternalAuthenticationActivated()) {
        LOGGER.error("current request not allowed with activated ldap authentication: '"
                + request.getRequestURI() + "'");
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        // ControllerHelper.sendRedirect(request, response, ClientUrlHelper
        // .renderUrl("/portal/home.do"));
    } else {
        result = super.showForm(request, response, errors);
        ControllerHelper.replaceModuleInMAV(result);
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:32,代码来源:BaseFormController.java

示例2: handleOnSubmit

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

    UserProfileNotificationsForm form = (UserProfileNotificationsForm) command;
    Long userId = SecurityHelper.getCurrentUserId();

    if (userId != null) {
        if (form.getAction().equals(FormAction.UPDATE_USER_PROFILE)) {
            doUpdateNotifications(request, response, form, errors);
        } else if (form.getAction().equals(FormAction.XMPP_REQUEST_FRIENDSHIP)) {
            doRequestFriendShip(userId);
        }
        saveNotificationSchedules(userId, request);
    }
    if (errors.hasErrors()) {
        return showForm(request, errors, getFormView());
    } else {
        MessageHelper.saveMessageFromKey(request, "user.profile.notification.save.success");
        return new ModelAndView(getSuccessView(), getCommandName(), command);
    }
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:26,代码来源:UserProfileNotificationsController.java

示例3: handleOnSubmit

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleOnSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    ModelAndView mav = null;
    ForgottenPWForm form = (ForgottenPWForm) command;
    if (!errors.hasErrors()) {
        if (StringUtils.equals(ForgottenPWForm.SEND_PW_LINK, form.getAction())) {
            mav = sendPasswordLink(request, errors, form);
        } else if (StringUtils.equals(ForgottenPWForm.CONFIRM_NEW_PASSWORD, form.getAction())) {
            String code = request.getParameter("code");
            mav = confirmNewPassword(request, errors, form, code);
        }
    }
    if (errors.hasErrors()) {
        mav = showForm(request, errors, getFormView());
    }
    if (mav == null) {
        mav = new ModelAndView(getFormView());

    }
    return mav;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:26,代码来源:ForgottenPWController.java

示例4: onSubmit

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    GroupVO form = (GroupVO) command;
    ModelAndView mav = null;
    if (ActionType.CREATE.equals(actionType)) {
        mav = handleCreate(request, form, errors);
    } else {
        mav = handleEdit(request, form, errors);
    }
    if (errors.hasErrors()) {
        if (errors.hasGlobalErrors()) {
            // save the first global error in request
            MessageHelper.saveErrorMessage(request, MessageHelper.getText(request, errors
                    .getGlobalError().getCode()));
        }
        ControllerHelper.setApplicationFailure(response);
        return showForm(request, response, errors);
    }
    ControllerHelper.setApplicationSuccess(response);
    return mav;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:26,代码来源:ClientUserGroupCreateAndEditController.java

示例5: processFinish

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @see org.springframework.web.servlet.mvc.AbstractWizardFormController#processFinish(javax.servlet
 *      .http.HttpServletRequest, javax.servlet.http.HttpServletResponse, Object,
 *      org.springframework.validation.BindException)
 */
@Override
protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {

    ModelAndView mav = null;

    // user account (the first admin)
    handleAdminAccount(request, command, errors);

    if (errors.hasErrors()) {
        // return to last installation step
        mav = showPage(request, errors, getCurrentPage(request));

    } else {
        // show finish view
        mav = showForm(request, errors, getFinishView());
    }

    // set some front end used values
    setProgressStatus(request, command, errors, getCurrentPage(request));

    return mav;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:31,代码来源:InstallationController.java

示例6: processFormSubmission

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView processFormSubmission(HttpServletRequest request,
        HttpServletResponse response, Object command, BindException errors) throws Exception {
    if (errors.hasErrors()) {
        ControllerHelper.setApplicationFailure(response);
    }
    return super.processFormSubmission(request, response, command, errors);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:12,代码来源:UserProfileChangeEmailController.java

示例7: processResult

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 *
 * @param request
 *            The request.
 * @param errors
 *            The errors.
 * @param errorMessage
 *            The error message.
 * @return The result.
 * @throws Exception
 *             Exception.
 */
private ModelAndView processResult(HttpServletRequest request, BindException errors,
        String errorMessage) throws Exception {
    if (errors.hasErrors()) {
        // return to initial page if errors occurred.
        return showPage(request, errors, 0);
    }
    ModelAndView result;
    if (StringUtils.isNotEmpty(errorMessage)) {
        result = new ModelAndView(getErrorView());
    } else {
        result = showForm(request, errors, getFinishView());
    }
    return result;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:27,代码来源:ConfirmUserController.java

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

示例9: createAccessCertificateDemo

import org.springframework.validation.BindException; //导入方法依赖的package包/类
/**
 * Create an access certificate without being authorized.
 * This method throws an error in production environments.
 *
 * @param request The payload
 * @return true if the certificate has been created successfully
 */

@PostMapping("/demo/access_certificates")
@ApiOperation(
        value = "Create an access certificate by providing an issuers private key - this endpoint is disabled in production mode.",
        produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
        consumes = MediaType.APPLICATION_JSON_UTF8_VALUE
)
@ApiResponses({
        @ApiResponse(code = OK_200, message = "Success", response = Boolean.class)
})
@ResponseStatus(HttpStatus.OK)
@PrometheusTimeMethod(name = "access_certificate_ctrl_create_access_certificate_demo", help = "")
public ResponseEntity<Boolean> createAccessCertificateDemo(
        @ApiParam(required = true) @RequestBody DemoCreateAccessCertificateRequestDto request) {

    boolean enableUnauthorizedAccess = !environment.acceptsProfiles("production");
    if (!enableUnauthorizedAccess) {
        return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).build();
    }

    requireNonNull(request);
    CreateAccessCertificateRequestDto createAccessCertificateRequestDto = requireNonNull(request.getRequest());

    log.info("Create demo access certificates with application {} for device {} and vehicle {}",
            createAccessCertificateRequestDto.getAppId(),
            createAccessCertificateRequestDto.getDeviceSerialNumber(),
            createAccessCertificateRequestDto.getVehicleSerialNumber());

    BindException errors = new BindException(createAccessCertificateRequestDto, "createAccessCertificateRequest");
    createAccessCertificateRequestValidator.validate(createAccessCertificateRequestDto, errors);
    if (errors.hasErrors()) {
        throw new BadRequestException(errors.getMessage());
    }

    IssuerEntity issuerEntity = issuerService.findIssuerByUuid(UUID.fromString(request.getIssuerId()))
            .orElseThrow(() -> new NotFoundException("IssuerEntity not found"));

    Key issuerPrivateKey = KeyImpl.fromBase64(request.getIssuerPrivateKeyBase64());
    IssuerNonceAuthentication issuerNonceAuthentication = demoService.createNonceAuthentication(IssuerWithKeys.builder()
            .privateKey(issuerPrivateKey)
            .publicKey(KeyImpl.fromBase64(issuerEntity.getPublicKeyBase64()))
            .issuer(issuerEntity)
            .build());

    CreateAccessCertificateContext createAccessCertificateContext = CreateAccessCertificateContext.builder()
            .appId(createAccessCertificateRequestDto.getAppId().toLowerCase())
            .deviceSerialNumber(createAccessCertificateRequestDto.getDeviceSerialNumber().toLowerCase())
            .vehicleSerialNumber(createAccessCertificateRequestDto.getVehicleSerialNumber().toLowerCase())
            .validityStart(createAccessCertificateRequestDto.getValidityStart())
            .validityEnd(createAccessCertificateRequestDto.getValidityEnd())
            .build();

    SignedAccessCertificateResource signedAccessCertificateResource = Optional.of(accessCertificateService
            .createAccessCertificate(issuerNonceAuthentication, createAccessCertificateContext)
            .flatMap(resource -> accessCertificateService.signAccessCertificate(resource, issuerPrivateKey)))
            .map(Mono::block)
            .orElseThrow(() -> new AmvAccessRuntimeException("Could not create access certificate",
                    new IllegalStateException("Access certificate is not present")));

    log.info("Successfully signed access certificate {}", signedAccessCertificateResource.getUuid());

    return ResponseEntity.ok(true);
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:71,代码来源:AccessCertificateCtrl.java


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