Java Code Examples for org.springframework.ui.ModelMap#get()
The following examples show how to use
org.springframework.ui.ModelMap#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceAct.java From Lottery with GNU General Public License v2.0 | 6 votes |
@RequestMapping(value = "/resource/v_list.do") public String list(HttpServletRequest request, ModelMap model) { CmsSite site = CmsUtils.getSite(request); String root = (String) model.get("root"); if (root == null) { root = RequestUtils.getQueryParam(request, "root"); } log.debug("list Resource root: {}", root); if (StringUtils.isBlank(root)) { root = site.getResPath(); } WebErrors errors = validateList(root, site.getResPath(), request); if (errors.hasErrors()) { return errors.showErrorPage(model); } String rel = root.substring(site.getResPath().length()); if (rel.length() == 0) { rel = "/"; } model.addAttribute("root", root); model.addAttribute("rel", rel); model.addAttribute("list", resourceMng.listFile(root, false)); return "resource/list"; }
Example 2
Source File: ErrorsMethodArgumentResolver.java From java-technology-stack with MIT License | 6 votes |
@Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Assert.state(mavContainer != null, "Errors/BindingResult argument only supported on regular handler methods"); ModelMap model = mavContainer.getModel(); String lastKey = CollectionUtils.lastElement(model.keySet()); if (lastKey != null && lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) { return model.get(lastKey); } throw new IllegalStateException( "An Errors/BindingResult argument is expected to be declared immediately after " + "the model attribute, the @RequestBody or the @RequestPart arguments " + "to which they apply: " + parameter.getMethod()); }
Example 3
Source File: TemplateAct.java From Lottery with GNU General Public License v2.0 | 6 votes |
@RequestMapping(value = "/template/v_list.do", method = RequestMethod.GET) public String list(HttpServletRequest request, ModelMap model) { CmsSite site = CmsUtils.getSite(request); String root = (String) model.get("root"); if (root == null) { root = RequestUtils.getQueryParam(request, "root"); } log.debug("list Template root: {}", root); if (StringUtils.isBlank(root)) { root = site.getTplPath(); } WebErrors errors = validateList(root, site.getTplPath(), request); if (errors.hasErrors()) { return errors.showErrorPage(model); } String rel = root.substring(site.getTplPath().length()); if (rel.length() == 0) { rel = "/"; } model.addAttribute("root", root); model.addAttribute("rel", rel); model.addAttribute("list", tplManager.getChild(root)); return "template/list"; }
Example 4
Source File: ErrorsMethodArgumentResolver.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { ModelMap model = mavContainer.getModel(); if (model.size() > 0) { int lastIndex = model.size()-1; String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex); if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) { return model.get(lastKey); } } throw new IllegalStateException( "An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " + "the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod()); }
Example 5
Source File: ResourceController.java From LodView with MIT License | 6 votes |
private void enrichResponse(ModelMap model, ResultBean r, HttpServletRequest req, HttpServletResponse res) { String publicUrl = r.getMainIRI(); res.addHeader("Link", "<" + publicUrl + ">; rel=\"about\""); @SuppressWarnings("unchecked") Map<String, Map<String, String>> rawdatalinks = (LinkedHashMap<String, Map<String, String>>) model.get("rawdatalinks"); for (String k : rawdatalinks.keySet()) { for (String k1 : rawdatalinks.get(k).keySet()) { res.addHeader("Link", "<" + rawdatalinks.get(k).get(k1) + ">; rel=\"alternate\"; type=\"application/rdf+xml\"; title=\"Structured Descriptor Document (" + k1 + ")\""); } } try { for (TripleBean t : r.getResources(r.getMainIRI()).get(r.getTypeProperty())) { res.addHeader("Link", "<" + t.getProperty().getProperty() + ">; rel=\"type\""); } } catch (Exception e) { // TODO: handle exception } }
Example 6
Source File: ErrorsMethodArgumentResolver.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { ModelMap model = mavContainer.getModel(); if (model.size() > 0) { int lastIndex = model.size()-1; String lastKey = new ArrayList<String>(model.keySet()).get(lastIndex); if (lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) { return model.get(lastKey); } } throw new IllegalStateException( "An Errors/BindingResult argument is expected to be declared immediately after the model attribute, " + "the @RequestBody or the @RequestPart arguments to which they apply: " + parameter.getMethod()); }
Example 7
Source File: ModelFactory.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Add {@link BindingResult} attributes to the model for attributes that require it. */ private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception { List<String> keyNames = new ArrayList<String>(model.keySet()); for (String name : keyNames) { Object value = model.get(name); if (isBindingCandidate(name, value)) { String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name; if (!model.containsAttribute(bindingResultKey)) { WebDataBinder dataBinder = dataBinderFactory.createBinder(request, value, name); model.put(bindingResultKey, dataBinder.getBindingResult()); } } } }
Example 8
Source File: ErrorsMethodArgumentResolver.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Assert.state(mavContainer != null, "Errors/BindingResult argument only supported on regular handler methods"); ModelMap model = mavContainer.getModel(); String lastKey = CollectionUtils.lastElement(model.keySet()); if (lastKey != null && lastKey.startsWith(BindingResult.MODEL_KEY_PREFIX)) { return model.get(lastKey); } throw new IllegalStateException( "An Errors/BindingResult argument is expected to be declared immediately after " + "the model attribute, the @RequestBody or the @RequestPart arguments " + "to which they apply: " + parameter.getMethod()); }
Example 9
Source File: ProjectControllerWebIntegrationTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 10
Source File: CmsFileAct.java From Lottery with GNU General Public License v2.0 | 5 votes |
@RequestMapping(value = "/file/v_list.do") public String list(HttpServletRequest request, ModelMap model) { CmsSite site = CmsUtils.getSite(request); String root = (String) model.get("root"); if (root == null) { root = RequestUtils.getQueryParam(request, "root"); } String valid=RequestUtils.getQueryParam(request, "valid"); Boolean validB=null; if(StringUtils.isNotBlank(valid)){ if(valid.equals("1")){ validB=true; }else{ validB=false; } } log.debug("list Resource root: {}", root); if (StringUtils.isBlank(root)) { root = site.getUploadPath(); } String uploadPath = root.substring(site.getUploadPath().length()); if (uploadPath.length() == 0) { uploadPath = "/"; } WebErrors errors = validateList(root, site.getUploadPath(), request); if (errors.hasErrors()) { return errors.showErrorPage(model); } model.addAttribute("root", root); model.addAttribute("rel", uploadPath); model.addAttribute("valid",validB); model.addAttribute("list", resourceMng.queryFiles(root, validB)); return "file/list"; }
Example 11
Source File: ProjectControllerNoWebAppTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list2() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 12
Source File: ProjectControllerNoWebAppTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 13
Source File: ProjectControllerWebAppTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list2() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 14
Source File: ProjectControllerWebAppTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 15
Source File: ProjectControllerWebIntegrationTests.java From spring-boot-practice with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void list2() throws Exception { MvcResult mvcResult = mockMvc.perform(get("/projects")) .andExpect(status().isOk()) .andExpect(model().attributeExists("list")) .andExpect(view().name("projects/list")) .andReturn(); ModelMap modelMap = mvcResult.getModelAndView().getModelMap(); Object listObj = modelMap.get("list"); assertThat(listObj, is(notNullValue())); assertThat(listObj, is(instanceOf(Page.class))); Page<Project> page = (Page<Project>) listObj; assertThat(page.getContent().size(), is(3)); }
Example 16
Source File: ModelFactory.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Add {@link BindingResult} attributes to the model for attributes that require it. */ private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception { List<String> keyNames = new ArrayList<String>(model.keySet()); for (String name : keyNames) { Object value = model.get(name); if (isBindingCandidate(name, value)) { String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name; if (!model.containsAttribute(bindingResultKey)) { WebDataBinder dataBinder = this.dataBinderFactory.createBinder(request, value, name); model.put(bindingResultKey, dataBinder.getBindingResult()); } } } }
Example 17
Source File: ModelFactory.java From java-technology-stack with MIT License | 5 votes |
/** * Add {@link BindingResult} attributes to the model for attributes that require it. */ private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception { List<String> keyNames = new ArrayList<>(model.keySet()); for (String name : keyNames) { Object value = model.get(name); if (value != null && isBindingCandidate(name, value)) { String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name; if (!model.containsAttribute(bindingResultKey)) { WebDataBinder dataBinder = this.dataBinderFactory.createBinder(request, value, name); model.put(bindingResultKey, dataBinder.getBindingResult()); } } } }
Example 18
Source File: MailinglistController.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
@RequestMapping("/{id:\\d+}/view.action") public String view(ComAdmin admin, @PathVariable int id, ModelMap model) throws Exception { if (id == 0) { return "redirect:/mailinglist/create.action"; } MailinglistForm form = null; if (model.containsKey("mailinglistForm")) { form = (MailinglistForm) model.get("mailinglistForm"); } else { Mailinglist mailinglist = mailinglistService.getMailinglist(id, admin.getCompanyID()); if (Objects.nonNull(mailinglist)) { form = conversionService.convert(mailinglist, MailinglistForm.class); } } if (form == null) { form = new MailinglistForm(); } else { RecipientProgressStatisticDto statistic = null; if (model.containsAttribute("statisticParams")) { statistic = (RecipientProgressStatisticDto) model.get("statisticParams"); } else { statistic = form.getStatistic(); } loadStatistics(admin, statistic, form, model); userActivityLogService.writeUserActivityLog(admin, "mailing list view", getDescription(form)); } model.addAttribute("mailinglistForm", form); return "mailinglist_view"; }
Example 19
Source File: ModelFactory.java From spring-analysis-note with MIT License | 5 votes |
/** * Add {@link BindingResult} attributes to the model for attributes that require it. */ private void updateBindingResult(NativeWebRequest request, ModelMap model) throws Exception { List<String> keyNames = new ArrayList<>(model.keySet()); for (String name : keyNames) { Object value = model.get(name); if (value != null && isBindingCandidate(name, value)) { String bindingResultKey = BindingResult.MODEL_KEY_PREFIX + name; if (!model.containsAttribute(bindingResultKey)) { WebDataBinder dataBinder = this.dataBinderFactory.createBinder(request, value, name); model.put(bindingResultKey, dataBinder.getBindingResult()); } } } }