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


Java BindingResult.reject方法代码示例

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


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

示例1: setPasswordPage

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/users/password", method = RequestMethod.POST)
public String setPasswordPage(@Valid UserPasswordDTO userPasswordDTO, BindingResult result, Model model,
                              RedirectAttributes attributes) {

    long userId = userPasswordDTO.getUserId();
    if (result.hasErrors()) {
        model.addAttribute("userDescription", getUserDescription(userId));
        return ADMIN_USERPASSWORD_VIEW;
    } else {
        if (!userPasswordDTO.getPassword().equals(userPasswordDTO.getRepeatedPassword())) {
            result.reject(GLOBAL_ERROR_PASSWORDS_DONOT_MATCH_KEY);
            model.addAttribute("userDescription", getUserDescription(userId));
            return ADMIN_USERPASSWORD_VIEW;
        } else {
            userService.updatePassword(userPasswordDTO);
            Optional<User> user = userService.getUserById(userPasswordDTO.getUserId());
            if (user.isPresent()) {
                webUI.addFeedbackMessage(attributes, FEEDBACK_USER_PASSWORD_UPDATED_KEY, user.get().getFirstName(),
                        user.get().getLastName());
            }
        }
    }
    return "redirect:/admin/users";
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:25,代码来源:AdminController.java

示例2: sendForgotEmail

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/users/forgotpassword", method = POST)
public String sendForgotEmail(@Valid ForgotEmailDTO forgotEmailDTO,
                              BindingResult result, Model model) {
    if (result.hasErrors()) {
        return USER_FORGOTPASSWORD_VIEW;
    } else {
        Optional<User> user = userService.getByEmail(forgotEmailDTO.getEmail());
        if (!user.isPresent()) {
            result.reject("global.error.email.does.not.exist");
        } else {

            model.addAttribute(FLASH_MESSAGE_KEY_FEEDBACK,
                    webUI.getMessage(FEEDBACK_PASSWORD_EMAIL_SENT));
            model.addAttribute("forgotEmailDTO", new ForgotEmailDTO());

            UserToken userToken = userService.createUserToken(user.get());
            fmMailService.sendResetPasswordMail(user.get(), userToken.getToken());
        }
    }
    return USER_FORGOTPASSWORD_VIEW;
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:22,代码来源:UserPasswordController.java

示例3: doValidate

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
private void doValidate() throws BindException {
	BindingResult errors = new BeanPropertyBindingResult(this,
			"resourceServerProperties");
	boolean jwtConfigPresent = StringUtils.hasText(this.jwt.getKeyUri())
			|| StringUtils.hasText(this.jwt.getKeyValue());
	boolean jwkConfigPresent = StringUtils.hasText(this.jwk.getKeySetUri());
	if (jwtConfigPresent && jwkConfigPresent) {
		errors.reject("ambiguous.keyUri",
				"Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should"
						+ " be configured.");
	}
	if (!jwtConfigPresent && !jwkConfigPresent) {
		if (!StringUtils.hasText(this.userInfoUri)
				&& !StringUtils.hasText(this.tokenInfoUri)) {
			errors.rejectValue("tokenInfoUri", "missing.tokenInfoUri",
					"Missing tokenInfoUri and userInfoUri and there is no "
							+ "JWT verifier key");
		}
		if (StringUtils.hasText(this.tokenInfoUri) && isPreferTokenInfo()) {
			if (!StringUtils.hasText(this.clientSecret)) {
				errors.rejectValue("clientSecret", "missing.clientSecret",
						"Missing client secret");
			}
		}
	}
	if (errors.hasErrors()) {
		throw new BindException(errors);
	}
}
 
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:30,代码来源:ResourceServerProperties.java

示例4: changePassword

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/users/resetpassword", method = POST)
public ModelAndView changePassword(@Valid @ModelAttribute("userPasswordDTO")
                                           UserPasswordDTO userPasswordDTO, BindingResult result) {
    ModelAndView mav = new ModelAndView();
    if (!result.hasErrors()) {

        ResetPasswordResult resetPasswordResult =
                userService.updatePassword(userPasswordDTO);

        switch (resetPasswordResult) {
            case ERROR:
                result.reject("global.error.password.reset");
                break;
            case FORGOT_SUCCESSFUL:
                mav.addObject(FLASH_MESSAGE_KEY_FEEDBACK,
                        webUI.getMessage(FEEDBACK_PASSWORD_LOGIN));
                break;
            case LOGGEDIN_SUCCESSFUL:
                mav.addObject(FLASH_MESSAGE_KEY_FEEDBACK,
                        webUI.getMessage(FEEDBACK_PASSWORD_RESET));
                break;
        }
    }

    mav.addObject("userPasswordDTO", userPasswordDTO);
    mav.setViewName(USER_CHANGEPASSWORD_VIEW);
    return mav;

}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:30,代码来源:UserPasswordController.java

示例5: createLinkPost

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/add/link", method = POST)
public String createLinkPost(@Valid PostDTO postDTO, BindingResult result,
                             CurrentUser currentUser, RedirectAttributes attributes, Model model,
                             HttpServletRequest request) throws DuplicatePostNameException {
    PagePreviewDTO pagePreview =
            (PagePreviewDTO) WebUtils.getSessionAttribute(request, "pagePreview");

    model.addAttribute("postheader", webUI.getMessage(ADD_LINK_HEADER));
    model.addAttribute("postFormType", "link");

    if (!isDuplicatePost(postDTO, null)) {
        if (result.hasErrors()) {
            model.addAttribute("hasLink", true);
            model.addAttribute("hasCarousel", true);
            model.addAttribute("pagePreview", pagePreview);
            if (result.hasFieldErrors("postTitle")) {
                postDTO.setPostTitle(pagePreview.getTitle());
            }
            model.addAttribute("postDTO", postDTO);
            return ADMIN_LINK_ADD_VIEW;
        } else {

            if (postDTO.getHasImages()) {
                if (postDTO.getDisplayType() != PostDisplayType.LINK) {
                    postDTO.setPostImage(
                            pagePreview.getImages().get(postDTO.getImageIndex()).src);
                } else
                    postDTO.setPostImage(null);
            }

            postDTO.setPostSource(PostUtils.createPostSource(postDTO.getPostLink()));
            postDTO.setPostName(PostUtils.createSlug(postDTO.getPostTitle()));
            postDTO.setUserId(currentUser.getId());
            postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));

            request.setAttribute("postTitle", postDTO.getPostTitle());
            Post post = postService.add(postDTO);

            postDTO.setPostId(post.getPostId());
            post.setPostMeta(jsoupService.createPostMeta(postDTO));

            // All links are saved as PUBLISHED so no _isPublished_ status check on new Links
            if (applicationSettings.getSolrEnabled())
                postDocService.addToIndex(post);

            // Links are included in Posts A-to-Z Listing
            fmService.createPostAtoZs();

            webUI.addFeedbackMessage(attributes, FEEDBACK_POST_LINK_ADDED);
            return "redirect:/admin/posts";
        }
    } else {
        result.reject("global.error.post.name.exists", new Object[]{postDTO.getPostTitle()}, "post name exists");
        model.addAttribute("hasLink", true);
        model.addAttribute("hasCarousel", true);
        model.addAttribute("pagePreview", pagePreview);
        return ADMIN_LINK_ADD_VIEW;
    }
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:60,代码来源:AdminPostsController.java

示例6: createPost

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/add/post", method = POST)
public String createPost(@Valid PostDTO postDTO, BindingResult result,
                         CurrentUser currentUser, RedirectAttributes attributes, Model model,
                         HttpServletRequest request) throws DuplicatePostNameException, PostNotFoundException {

    String saveAction = request.getParameter("post");

    model.addAttribute("postheader", webUI.getMessage(ADD_POST_HEADER));
    model.addAttribute("hasPost", true);
    model.addAttribute("canPreview", false);

    Post sessionPost = null;
    Object obj = WebUtils.getSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST);
    if (obj != null) {
        sessionPost = (Post) WebUtils.getSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST);
    }
    if (!isDuplicatePost(postDTO, sessionPost)) {
        if (result.hasErrors()) {
            model.addAttribute("postDTO", postDTO);
            return ADMIN_POST_ADD_VIEW;
        } else {
            postDTO.setDisplayType(postDTO.getDisplayType());
            postDTO.setPostName(PostUtils.createSlug(postDTO.getPostTitle()));
            postDTO.setUserId(currentUser.getId());
            postDTO.setPostContent(cleanContentTailHtml(postDTO.getPostContent()));
            postDTO.setIsPublished(saveAction.equals(POST_PUBLISH));
            postDTO.setTwitterCardType(postDTO.getTwitterCardType());
            postDTO.setCategoryId(postDTO.getCategoryId());

            request.setAttribute("postTitle", postDTO.getPostTitle());
            Post saved;

            if (sessionPost == null)
                saved = postService.add(postDTO);
            else {
                postDTO.setPostId(sessionPost.getPostId());
                saved = postService.update(postDTO);
            }

            postDTO.setPostId(saved.getPostId());

            if (sessionPost == null)
                saved.setPostMeta(jsoupService.createPostMeta(postDTO));
            else
                saved.setPostMeta(jsoupService.updatePostMeta(postDTO));

            WebUtils.setSessionAttribute(request, SESSION_ATTRIBUTE_NEWPOST, saved);

            if (saveAction.equals(POST_PUBLISH)) {

                if (saved.getIsPublished()) {
                    if (applicationSettings.getSolrEnabled()) {
                        postDocService.addToIndex(saved);
                    }
                    fmService.createPostAtoZs();
                }

                webUI.addFeedbackMessage(attributes, FEEDBACK_POST_POST_ADDED);
                return "redirect:/admin/posts";
            } else {
                model.addAttribute("fileuploading", fmService.getFileUploadingScript());
                model.addAttribute("fileuploaded", fmService.getFileUploadedScript());
                model.addAttribute("postDTO", getUpdatedPostDTO(saved));
                model.addAttribute("hasImageUploads", true);
                model.addAttribute("canPreview", true);
                model.addAttribute("postName", saved.getPostName());
                model.addAttribute("categories", postService.getAdminSelectionCategories());
                return ADMIN_POST_ADD_VIEW;
            }
        }
    } else {
        model.addAttribute("hasImageUploads", true);
        result.reject("global.error.post.name.exists", new Object[]{postDTO.getPostTitle()}, "post name exists");
        return ADMIN_POST_ADD_VIEW;
    }
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:77,代码来源:AdminPostsController.java

示例7: create

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
/**
 * Process the send form.
 */
@PostMapping
public ModelAndView create(final HttpServletRequest req,
                           final RedirectAttributes redirectAttributes)
    throws IOException, FileUploadException {

    if (!ServletFileUpload.isMultipartContent(req)) {
        throw new IllegalStateException("No multipart request!");
    }

    // Create encryptionKey and initialization vector (IV) to encrypt data
    final KeyIv encryptionKey = messageService.newEncryptionKey();

    // secret shared with receiver using the link - not stored in database
    final String linkSecret = messageService.newRandomId();

    final DataBinder binder = initBinder();

    final List<SecretFile> tmpFiles = handleStream(req, encryptionKey, binder);

    final EncryptMessageCommand command = (EncryptMessageCommand) binder.getTarget();
    final BindingResult errors = binder.getBindingResult();

    if (!errors.hasErrors()
        && command.getMessage() == null
        && (tmpFiles == null || tmpFiles.isEmpty())) {
        errors.reject(null, "Neither message nor files submitted");
    }

    if (errors.hasErrors()) {
        return new ModelAndView(FORM_SEND_MSG, binder.getBindingResult().getModel());
    }

    final String senderId = messageService.storeMessage(command.getMessage(), tmpFiles,
        encryptionKey, HashCode.fromString(linkSecret).asBytes(), command.getPassword(),
        Instant.now().plus(command.getExpirationDays(), ChronoUnit.DAYS));

    redirectAttributes
        .addFlashAttribute("messageSent", true)
        .addFlashAttribute("message", command.getMessage());

    return
        new ModelAndView("redirect:/send/" + senderId)
        .addObject("linkSecret", linkSecret);
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:48,代码来源:SendController.java

示例8: handleStream

import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
private List<SecretFile> handleStream(final HttpServletRequest req,
                                      final KeyIv encryptionKey, final DataBinder binder)
    throws FileUploadException, IOException {

    final BindingResult errors = binder.getBindingResult();

    final MutablePropertyValues propertyValues = new MutablePropertyValues();
    final List<SecretFile> tmpFiles = new ArrayList<>();

    @SuppressWarnings("checkstyle:anoninnerlength")
    final AbstractMultipartVisitor visitor = new AbstractMultipartVisitor() {

        private OptionalInt expiration = OptionalInt.empty();

        @Override
        void emitField(final String name, final String value) {
            propertyValues.addPropertyValue(name, value);

            if ("expirationDays".equals(name)) {
                expiration = OptionalInt.of(Integer.parseInt(value));
            }
        }

        @Override
        void emitFile(final String fileName, final InputStream inStream) {
            final Integer expirationDays = expiration
                .orElseThrow(() -> new IllegalStateException("No expirationDays configured"));

            tmpFiles.add(messageService.encryptFile(fileName, inStream, encryptionKey,
                Instant.now().plus(expirationDays, ChronoUnit.DAYS)));
        }

    };

    try {
        visitor.processRequest(req);
        binder.bind(propertyValues);
        binder.validate();
    } catch (final IllegalStateException ise) {
        errors.reject(null, ise.getMessage());
    }

    return tmpFiles;
}
 
开发者ID:osiegmar,项目名称:setra,代码行数:45,代码来源:SendController.java


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