本文整理匯總了Java中org.springframework.validation.BindingResult.hasFieldErrors方法的典型用法代碼示例。如果您正苦於以下問題:Java BindingResult.hasFieldErrors方法的具體用法?Java BindingResult.hasFieldErrors怎麽用?Java BindingResult.hasFieldErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.validation.BindingResult
的用法示例。
在下文中一共展示了BindingResult.hasFieldErrors方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}