本文整理汇总了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;
}
}