@Override @RequestMapping(value = "/{id}", method = RequestMethod.POST) public String saveEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value="id") String id, @ModelAttribute(value="entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception { String templatePath = super.saveEntity(request, response, model, pathVars, id, entityForm, result, ra); if (result.hasErrors()) { model.addAttribute("cmsUrlPrefix", staticAssetService.getStaticAssetUrlPrefix()); } return templatePath; }
private Object getErrors(MethodParameter parameter, BindingContext context) { Assert.isTrue(parameter.getParameterIndex() > 0, "Errors argument must be declared immediately after a model attribute argument"); int index = parameter.getParameterIndex() - 1; MethodParameter attributeParam = MethodParameter.forExecutable(parameter.getExecutable(), index); ReactiveAdapter adapter = getAdapterRegistry().getAdapter(attributeParam.getParameterType()); Assert.state(adapter == null, "An @ModelAttribute and an Errors/BindingResult argument " + "cannot both be declared with an async type wrapper. " + "Either declare the @ModelAttribute without an async wrapper type or " + "handle a WebExchangeBindException error signal through the async type."); ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class); String name = (ann != null && StringUtils.hasText(ann.value()) ? ann.value() : Conventions.getVariableNameForParameter(attributeParam)); Object errors = context.getModel().asMap().get(BindingResult.MODEL_KEY_PREFIX + name); Assert.state(errors != null, () -> "An Errors/BindingResult argument is expected " + "immediately after the @ModelAttribute argument to which it applies. " + "For @RequestBody and @RequestPart arguments, please declare them with a reactive " + "type wrapper and use its onError operators to handle WebExchangeBindException: " + parameter.getMethod()); return errors; }
@RequestMapping( value = "/{id}/{collectionField:.*}/{collectionItemId}/{tab:[0-9]+}/{tabName}", method = RequestMethod.POST ) public String viewCollectionItemTab(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value="id") String id, @PathVariable(value="collectionField") String collectionField, @PathVariable(value="collectionItemId") String collectionItemId, @PathVariable(value="tabName") String tabName, @ModelAttribute(value = "entityForm") EntityForm entityForm) throws Exception { return showViewUpdateCollection(request, model, pathVars, id, collectionField, collectionItemId, ModalHeaderType.VIEW_COLLECTION_ITEM.getType(), entityForm, null); }
@RequestMapping(value="viewPhone", method = { RequestMethod.GET, RequestMethod.POST} public String viewPhone(@RequestParam(required = false) Long customerPhoneId, HttpServletRequest request, @ModelAttribute("phoneNameForm") PhoneNameForm phoneNameForm, BindingResult errors) { if (customerPhoneId == null) {
@RequestMapping(method = RequestMethod.GET) @ApiOperation(value = "List all environments") public ListEnvironmentsResponse listEnvironments( @PathVariable("cluster") String cluster, @RequestParam(value = "environmentNamePrefix", required = false) String environmentNamePrefix, @ModelAttribute RequestPagination pagination) throws ServiceException, ClientException { // TODO: Add validation for cluster. Add Validation for environmentNamePrefix return mapper.fromDataServiceResponse( dataService.listEnvironments( mapper.toListEnvironmentsRequest( getApiGatewayRequestContext(), cluster, environmentNamePrefix))); }
@RequestMapping(value = "/path1/path2", method = RequestMethod.POST) @ModelAttribute("attr2") public Date handle(C date, Model model) throws Exception { return (Date) date; }
/** * Invoked when the translation button is clicked on a given translatable field * * @param request * @param response * @param model * @param form * @param result * @return the return view path * @throws Exception */ @RequestMapping(value = "", method = RequestMethod.GET) public String viewTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception { if (extensionManager != null) { extensionManager.getProxy().applyTransformation(form); } adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH); List<Translation> translations = translationService.getTranslations(form.getCeilingEntity(), form.getEntityId(), form.getPropertyName()); ListGrid lg = formService.buildListGrid(translations, form.getIsRte()); model.addAttribute("currentUrl", request.getRequestURL().toString()); model.addAttribute("form", form); model.addAttribute("listGrid", lg); model.addAttribute("viewType", "modal/translationListGrid"); model.addAttribute("modalHeaderType", ModalHeaderType.TRANSLATION.getType()); return "modules/modalContainer"; }
@Override @RequestMapping("/myPath.do") public String myHandle(@ModelAttribute("myCommand") @Valid TestBean tb, BindingResult errors, ModelMap model) { if (!errors.hasFieldErrors("validCountry")) { throw new IllegalStateException("Declarative validation not applied"); } return super.myHandle(tb, errors, model); }
@RequestMapping(value = "/user", params = {"notInGroupId", "pattern"}, method = RequestMethod.GET) @ResponseBody public JsonResponse findUserNotInGroup(@RequestParam("notInGroupId") long notInGroupId, @Valid @ModelAttribute SearchQueryDto searchQueryDto, BindingResult result) { checkForAdminPermissions(); if (result.hasFieldErrors() || result.hasGlobalErrors()) { return new JsonResponse(JsonResponseStatus.FAIL, result.getAllErrors()); } List<UserDto> users = userService.findByUsernameOrEmailNotInGroup(searchQueryDto.getPattern(), notInGroupId, 10); return new JsonResponse(JsonResponseStatus.SUCCESS, users); }
@RequestMapping(value = {"/verify.do"}, method = RequestMethod.POST) public ModelAndView validateCode(Model model, @RequestParam("code") String code, @ModelAttribute("uaaMfaCredentials") UserGoogleMfaCredentials credentials, SessionStatus sessionStatus) throws UaaPrincipalIsNotInSession { model.addAttribute("error", "Incorrect code, please try again."); } catch (NumberFormatException | GoogleAuthenticatorException e) { logger.debug("Error validating the code for user: " + uaaPrincipal.getId() + ". Error: " + e.getMessage()); publish(new MfaAuthenticationFailureEvent(getUaaUser(uaaPrincipal), uaaAuth, getMfaProvider().getType().toValue())); model.addAttribute("error", "Incorrect code, please try again.");
@RequestMapping("/myPath.do") @ModelAttribute("yourKey") public String myHandle(@ModelAttribute("myCommand") TestBean tb, BindingResult errors, Model model) { if (!model.containsAttribute("myKey")) { model.addAttribute("myKey", "myValue"); } return "yourValue"; } }
@RequestMapping(value="savePhone", method = { RequestMethod.GET, RequestMethod.POST} public String savePhone(@ModelAttribute("phoneNameForm") PhoneNameForm phoneNameForm, BindingResult errors, HttpServletRequest request, @RequestParam(required = false) Long customerPhoneId, @RequestParam(required = false) Long phoneId) { if (GenericValidator.isBlankOrNull(phoneNameForm.getPhoneName())) { errors.pushNestedPath("phone"); phoneValidator.validate(phoneNameForm.getPhone(), errors); errors.popNestedPath(); if (!errors.hasErrors()) { CustomerPhone customerPhone = (CustomerPhone) entityConfiguration.createEntityInstance("org.broadleafcommerce.profile.core.domain.CustomerPhone"); customerPhone.setCustomer(customerState.getCustomer(request));
@RequestMapping("/myPath.do") public String myHandle(@ModelAttribute(name="myCommand", binding=true) TestBean tb, BindingResult errors, ModelMap model) { FieldError error = errors.getFieldError("age"); assertNotNull("Must have field error for age property", error); assertEquals("value2", error.getRejectedValue()); if (!model.containsKey("myKey")) { model.addAttribute("myKey", "myValue"); } return "myView"; } }
public String handle( @CookieValue("cookie") int cookieV, @PathVariable("pathvar") String pathvarV, @RequestHeader("header") String headerV, @RequestHeader(defaultValue = "#{systemProperties.systemHeader}") String systemHeader, @RequestHeader Map<String, Object> headerMap, @RequestParam("dateParam") Date dateParam, @RequestParam Map<String, Object> paramMap, String paramByConvention, @Value("#{request.contextPath}") String value, @ModelAttribute("modelAttr") @Valid TestBean modelAttr, Errors errors, TestBean modelAttrByConvention, @RequestAttribute TestBean requestAttribute, User user, @ModelAttribute OtherUser otherUser, Model model, UriComponentsBuilder builder) { model.addAttribute("cookie", cookieV).addAttribute("pathvar", pathvarV).addAttribute("header", headerV) .addAttribute("systemHeader", systemHeader).addAttribute("headerMap", headerMap) .addAttribute("dateParam", dateParam).addAttribute("paramMap", paramMap)
@RequestMapping(value="registerCustomer", method = { RequestMethod.POST }) public ModelAndView registerCustomer(@ModelAttribute("registerCustomerForm") RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response) { registerCustomerValidator.validate(registerCustomerForm, errors); if (! errors.hasErrors()) { customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm()); loginService.loginCustomer(registerCustomerForm.getCustomer()); return new ModelAndView(getRegistrationSuccessView()); } else { return new ModelAndView(getRegistrationErrorView()); } }
@ModelAttribute("owner") public Owner findOwner(@PathVariable("ownerId") int ownerId) { return this.owners.findById(ownerId); }
@SuppressWarnings("unused") @ModelAttribute public void addAttributes(Model model) { model.addAttribute("attr2", "gAttr2"); } }
ModelAttribute ann = parameter.getParameterAnnotation(ModelAttribute.class); if (ann != null) { mavContainer.setBinding(name, ann.binding()); if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) { throw new BindException(binder.getBindingResult()); Map<String, Object> bindingResultModel = bindingResult.getModel(); mavContainer.removeAttributes(bindingResultModel); mavContainer.addAllAttributes(bindingResultModel);
private String getNameForReturnValue(MethodParameter returnType) { return Optional.ofNullable(returnType.getMethodAnnotation(ModelAttribute.class)) .filter(ann -> StringUtils.hasText(ann.value())) .map(ModelAttribute::value) .orElseGet(() -> Conventions.getVariableNameForParameter(returnType)); }