本文整理汇总了Java中org.springframework.validation.BindingResult.rejectValue方法的典型用法代码示例。如果您正苦于以下问题:Java BindingResult.rejectValue方法的具体用法?Java BindingResult.rejectValue怎么用?Java BindingResult.rejectValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.BindingResult
的用法示例。
在下文中一共展示了BindingResult.rejectValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEvent
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
RedirectAttributes redirectAttributes) {
if (result.hasErrors()) {
return "events/create";
}
CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
if (attendee == null) {
result.rejectValue("attendeeEmail", "attendeeEmail.missing",
"Could not find a user for the provided Attendee Email");
}
if (result.hasErrors()) {
return "events/create";
}
Event event = new Event();
event.setAttendee(attendee);
event.setDescription(createEventForm.getDescription());
event.setOwner(userContext.getCurrentUser());
event.setSummary(createEventForm.getSummary());
event.setWhen(createEventForm.getWhen());
calendarService.createEvent(event);
redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
return "redirect:/events/my";
}
示例2: registrar_Organizador
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/registrar_organizador", method = RequestMethod.POST)
public String registrar_Organizador(@Valid Organizador organizador, BindingResult bindingResult, Model model, HttpSession session) {
if (bindingResult.hasErrors()) {
model.addAttribute("tipoUsuario", "organizador");
return "register";
}
organizador.setPassword(passwordEncoder.encode(organizador.getPassword()));
organizador.setRoles("USER,ORGANIZADOR");
Contexto contexto = FactoriaComandos.getInstance().crearComando(EventosNegocio.CREAR_USUARIO).execute(organizador);
if(contexto.getEvento() == EventosNegocio.USUARIO_CREADO){
return "redirect:/login";
}else if(contexto.getEvento() == EventosNegocio.EMAIL_YA_EXISTENTE){
model.addAttribute("tipoUsuario", "organizador");
bindingResult.rejectValue("email" , "error.organizador", "Email ya existente en el sistema");
return "register";
}else{
model.addAttribute("pagina", "error-500");
return "error-500";
}
}
示例3: signup
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@PostMapping(value="/signup/new")
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
if(result.hasErrors()) {
return "signup/form";
}
String email = signupForm.getEmail();
if(calendarService.findUserByEmail(email) != null) {
result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
return "signup/form";
}
CalendarUser user = new CalendarUser();
user.setEmail(email);
user.setFirstName(signupForm.getFirstName());
user.setLastName(signupForm.getLastName());
user.setPassword(signupForm.getPassword());
logger.info("CalendarUser: {}", user);
int id = calendarService.createUser(user);
user.setId(id);
userContext.setCurrentUser(user);
redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
return "redirect:/";
}
示例4: signup
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value="/signup/new",method=RequestMethod.POST)
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
if(result.hasErrors()) {
return "signup/form";
}
String email = signupForm.getEmail();
if(calendarService.findUserByEmail(email) != null) {
result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
return "signup/form";
}
CalendarUser user = new CalendarUser();
user.setEmail(email);
user.setFirstName(signupForm.getFirstName());
user.setLastName(signupForm.getLastName());
user.setPassword(signupForm.getPassword());
logger.info("CalendarUser: {}", user);
int id = calendarService.createUser(user);
user.setId(id);
userContext.setCurrentUser(user);
redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
return "redirect:/";
}
示例5: signup
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value="/signup/new", method=RequestMethod.POST)
public String signup(final @Valid SignupForm signupForm,
final BindingResult result,
RedirectAttributes redirectAttributes) {
if(result.hasErrors()) {
return "signup/form";
}
String email = signupForm.getEmail();
if(calendarService.findUserByEmail(email) != null) {
result.rejectValue("email", "errors.signup.email", "Email address is already in use. FOO");
redirectAttributes.addFlashAttribute("error", "Email address is already in use. FOO");
return "signup/form";
}
CalendarUser user = new CalendarUser();
user.setEmail(email);
user.setFirstName(signupForm.getFirstName());
user.setLastName(signupForm.getLastName());
user.setPassword(signupForm.getPassword());
int id = calendarService.createUser(user);
user.setId(id);
userContext.setCurrentUser(user);
redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
return "redirect:/";
}
示例6: createEvent
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@PostMapping(value = "/new")
public Map<String, List<?>> createEvent(@Valid CreateEventForm createEventForm,
BindingResult bindingResult,
RedirectAttributes redirectAttributes) {
Map<String, List<?>> result = new HashMap<>();
if (bindingResult.hasErrors()) {
result.put("bindingResultErrors", bindingResult.getFieldErrors());
return result;
}
CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
if (attendee == null) {
bindingResult.rejectValue("attendeeEmail", "attendeeEmail.missing",
"Could not find a user for the provided Attendee Email");
}
if (bindingResult.hasErrors()) {
result.put("bindingResultErrors", bindingResult.getFieldErrors());
}
Event event = new Event();
event.setAttendee(attendee);
event.setDescription(createEventForm.getDescription());
event.setOwner(userContext.getCurrentUser());
event.setSummary(createEventForm.getSummary());
event.setWhen(createEventForm.getWhen());
int eventId = calendarService.createEvent(event);
List<String> success = new ArrayList<>();
success.add(String.valueOf(eventId));
success.add("Successfully added the new event");
result.put("message", success);
return result;
}
示例7: processFindForm
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/products/list", method = RequestMethod.GET)
public String processFindForm(UserQuery userQuery, BindingResult result, Model model, HttpServletRequest request) {
List<Product> results = null;
Boolean isSimpleTermQuery = userQuery.getQuery().matches("[a-zA-Z_0-9 ]*");
if (StringUtils.isEmpty(userQuery.getQuery())) {
return "redirect:/products/search";
} else
try {
if (isSimpleTermQuery) {
HighlightPage<Product> highlightedResults = productService
.findByHighlightedNameCriteria(userQuery.getQuery());
results = SolrUtils.highlightPagesToList(highlightedResults);
} else {
results = productService.getProductsWithUserQuery(userQuery.getQuery());
}
} catch (UncategorizedSolrException ex) {
logger.info(MessageFormat.format("Bad Query: {0}", userQuery.getQuery()));
result.rejectValue("query", "product.search.error", new Object[] { userQuery.getQuery() }, "not found");
return PRODUCT_SEARCH_VIEW;
}
if (results.size() < 1) {
result.rejectValue("query", "product.search.noresults", new Object[] { userQuery.getQuery() }, "not found");
return PRODUCT_SEARCH_VIEW;
}
if (results.size() > 1) {
PagedListHolder<Product> pagedListHolder = new PagedListHolder<Product>(results);
pagedListHolder.setPageSize(PRODUCT_LIST_PAGE_SIZE);
request.getSession().setAttribute(SESSION_ATTRIBUTE_PRODUCTLIST, pagedListHolder);
return "redirect:/products/page/1";
} else {
Product product = results.iterator().next();
return "redirect:/products/" + product.getId();
}
}
示例8: addmember
import org.springframework.validation.BindingResult; //导入方法依赖的package包/类
@RequestMapping(value = "/addteam", method = RequestMethod.POST)
public ModelAndView addmember(@Valid @ModelAttribute("teamEvent") TeamEvent teamEvent,
BindingResult bindingResult) {
ModelAndView modelAndView = new ModelAndView();
Team newTeamEvent = eventService.addTeam(teamEvent.getEventId(), teamEvent.getTeamName());
if (newTeamEvent == null) {
bindingResult.rejectValue("teamName", "invalid.team.name", "invalid team name");
}
Event event = eventService.find(teamEvent.getEventId());
modelAndView.addObject("teamEvent", teamEvent);
modelAndView.addObject("event", event);
modelAndView.setViewName("event/edit");
return modelAndView;
}