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


Java BindingResult.rejectValue方法代码示例

本文整理汇总了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";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:25,代码来源:EventsController.java

示例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";
    }

}
 
开发者ID:EventSoftGroup,项目名称:EventSoft,代码行数:26,代码来源:UserController.java

示例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:/";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:28,代码来源:SignupController.java

示例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:/";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:28,代码来源:SignupController.java

示例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:/";
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:29,代码来源:SignupController.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-Security-Third-Edition,代码行数:38,代码来源:EventsController.java

示例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();
	}
}
 
开发者ID:mintster,项目名称:nixmash-blog,代码行数:39,代码来源:SolrController.java

示例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;
}
 
开发者ID:garydamm,项目名称:idea-forge,代码行数:15,代码来源:EventController.java


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