@RequestMapping("/hello") public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) { model.addAttribute("name", name); return "hello"; } }
@SuppressWarnings("unused") @ModelAttribute public void addAttributes(Model model) { model.addAttribute("attr1", "gAttr1"); model.addAttribute("attr2", "gAttr2"); } }
@RequestMapping("/toEdit") public String toEdit(Model model,Long id) { User user=userService.findUserById(id); model.addAttribute("user", user); return "user/userEdit"; }
@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; }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public String show(@PathVariable("id") Long id, Model model) { model.addAttribute("loanshark", LoanShark.findLoanShark(id)); model.addAttribute("itemId", id); return "loansharks/show"; }
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Model model) { LoanShark.findLoanShark(id).remove(); model.addAttribute("page", (page == null) ? "1" : page.toString()); model.addAttribute("size", (size == null) ? "10" : size.toString()); return "redirect:/loansharks?page=" + ((page == null) ? "1" : page.toString()) + "&size=" + ((size == null) ? "10" : size.toString()); }
@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 = "/change_email.do", method = RequestMethod.POST) public String changeEmail(Model model, @Valid @ModelAttribute("newEmail") ValidEmail newEmail, BindingResult result, @RequestParam(required = false, value = "client_id") String clientId, @RequestParam(required = false, value = "redirect_uri") String redirectUri, RedirectAttributes redirectAttributes, HttpServletResponse response) { SecurityContext securityContext = SecurityContextHolder.getContext(); model.addAttribute("error_message_code", "invalid_email"); model.addAttribute("email", ((UaaPrincipal)securityContext.getAuthentication().getPrincipal()).getEmail()); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return "change_email"; } catch (UaaException e) { if (e.getHttpStatus() == 409) { model.addAttribute("error_message_code", "username_exists"); model.addAttribute("email", ((UaaPrincipal)securityContext.getAuthentication().getPrincipal()).getEmail()); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return "change_email";
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) .addAttribute("paramByConvention", paramByConvention).addAttribute("value", value) .addAttribute("customArg", customArg).addAttribute(user) .addAttribute("sessionAttribute", sessionAttribute) .addAttribute("requestAttribute", requestAttribute) .addAttribute("url", builder.path("/path").build().toUri());
@GetMapping("/owners/{ownerId}/edit") public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { Owner owner = this.owners.findById(ownerId); model.addAttribute(owner); return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; }
@GetMapping("") public String index(@RequestParam(defaultValue = "0") int page, Model model) { Page<Post> posts = postRepository.findAll(new PageRequest(page, PAGE_SIZE, Sort.Direction.DESC, "id")); model.addAttribute("totalPages", posts.getTotalPages()); model.addAttribute("page", page); model.addAttribute("posts", posts); return "admin/posts/index"; }
@RequestMapping("/hello") public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) { model.addAttribute("name", name); return "hello"; } }
/** * Renders a modal dialog that has a list grid of translations for the specified field * * @param request * @param response * @param model * @param form * @param result * @return the return view path * @throws Exception */ @RequestMapping(value = "/add", method = RequestMethod.GET) public String showAddTranslation(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute(value = "form") TranslationForm form, BindingResult result) throws Exception { String sectionKey = getSectionKey(pathVars); String sectionClassName = getClassNameForSection(sectionKey); List<SectionCrumb> sectionCrumbs = new ArrayList<>(); PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars); ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData(); adminRemoteSecurityService.securityCheck(form.getCeilingEntity(), EntityOperationType.FETCH); EntityForm entityForm = formService.buildTranslationForm(cmd, form, TranslationFormAction.ADD); model.addAttribute("entityForm", entityForm); model.addAttribute("viewType", "modal/translationAdd"); model.addAttribute("currentUrl", request.getRequestURL().toString()); model.addAttribute("modalHeaderType", ModalHeaderType.ADD_TRANSLATION.getType()); return "modules/modalContainer"; }
@RequestMapping(value = "/circuit/{id}", method = RequestMethod.GET) public String getCircuit(@PathVariable String id, Model model) { model.addAttribute("receivedId", id); return "result"; } }
@RequestMapping(value = "{tagName}", method = GET) public String showTag(@PathVariable String tagName, @RequestParam(defaultValue = "1") int page, Model model) { Tag tag = tagService.getTag(tagName); if (tag == null) { throw new NotFoundException("Tag " + tagName + " is not found."); } page = page < 1 ? 0 : page - 1; Page<Post> posts = postService.findPostsByTag(tagName, page, appSetting.getPageSize()); model.addAttribute("tag", tag); model.addAttribute("posts", posts); model.addAttribute("page", page + 1); model.addAttribute("totalPages", posts.getTotalPages()); return "tags/show"; } }
@RequestMapping("/list") public String list(Model model) { List<User> users=userService.getUserList(); model.addAttribute("users", users); return "user/list"; }
/** * 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"; }
@RequestMapping(value = "/create_account.do", method = POST) public String sendActivationEmail(Model model, HttpServletResponse response, @RequestParam(value = "client_id", required = false) String clientId, @RequestParam(value = "redirect_uri", required = false) String redirectUri, @Valid @ModelAttribute("email") ValidEmail email, BindingResult result, @RequestParam("password") String password, @RequestParam("password_confirmation") String passwordConfirmation, @RequestParam(value = "does_user_consent", required = false) boolean doesUserConsent) { identityProviderList = identityProviderList.stream().filter(idp -> !idp.getOriginKey().equals(OriginKeys.UAA)).collect(Collectors.toList()); if(!identityProviderList.isEmpty()) { model.addAttribute("email", email.getEmail()); return handleUnprocessableEntity(model, response, "error_message_code", "other_idp");
@GetMapping("/person/{name}") public String show(@PathVariable String name, Model model) { Person person = new Person(name); model.addAttribute(person); return "person/show"; } }
@GetMapping(value = "") public String index(@RequestParam(defaultValue = "1") int page, Model model) { page = page < 1 ? 0 : page - 1; Page<Post> posts = postService.getAllPublishedPostsByPage(page, appSetting.getPageSize()); model.addAttribute("totalPages", posts.getTotalPages()); model.addAttribute("posts", posts); model.addAttribute("page", page + 1); return "home/home"; } }