當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。