Java Code Examples for org.springframework.ui.ModelMap#containsAttribute()
The following examples show how to use
org.springframework.ui.ModelMap#containsAttribute() .
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: 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 2
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()); } } } }
Example 3
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 4
Source File: ProfileFieldsController.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
@RequestMapping("/profiledb/{fieldname}/view.action") public String view(ComAdmin admin, @PathVariable("fieldname") String fieldName, ModelMap model) { final int companyId = admin.getCompanyID(); ComProfileField field = profileFieldService.getProfileField(companyId, fieldName); if (!model.containsAttribute("profileForm")) { ProfileFieldForm form; if (field == null) { return "redirect:/profiledb/new.action"; } form = conversionService.convert(field, ProfileFieldForm.class); form.setFieldname(fieldName); if (field.getHistorize()) { form.setDependentWorkflowName(profileFieldService.getTrackingDependentWorkflows(companyId, fieldName)); } model.addAttribute("profileForm", form); } String creationDate = ""; String changeDate = ""; if (field != null) { creationDate = DateUtilities.format(field.getCreationDate(), admin.getDateTimeFormat()); changeDate = DateUtilities.format(field.getChangeDate(), admin.getDateTimeFormat()); } model.addAttribute("HISTORY_FEATURE_ENABLED", configService.isRecipientProfileHistoryEnabled(companyId)); model.addAttribute("creationDate", creationDate); model.addAttribute("fieldsWithIndividualSortOrder", profileFieldService.getFieldWithIndividualSortOrder(companyId, admin.getAdminID())); model.addAttribute("changeDate", changeDate); return "settings_profile_field_view"; }
Example 5
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 6
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 7
Source File: UsersController.java From JavaSpringMvcBlog with MIT License | 5 votes |
@RequestMapping(value = "/settings", method = RequestMethod.GET) public String showEditSettingsPage(ModelMap model) { if (!model.containsAttribute("user")) { User user = userService.currentUser(); if (user == null) { return "redirect:posts"; } model.addAttribute("user", user); } return "settings"; }
Example 8
Source File: UsersController.java From JavaSpringMvcBlog with MIT License | 5 votes |
@RequestMapping(value = "/edit_profile", method = RequestMethod.GET) public String showEditProfilePage(ModelMap model) { if (!model.containsAttribute("user")) { User user = userService.currentUser(); if (user == null) { return "redirect:posts"; } model.addAttribute("user", user); } return "editprofile"; }
Example 9
Source File: CredentialsManagementController.java From airsonic-advanced with GNU General Public License v3.0 | 4 votes |
@ModelAttribute protected void displayForm(Authentication user, ModelMap map) { List<CredentialsCommand> creds = securityService.getCredentials(user.getName(), App.values()) .parallelStream() .map(CredentialsCommand::fromUserCredential) .map(c -> { if (c.getEncoder().startsWith("legacy")) { c.addDisplayComment("migratecred"); } if (GlobalSecurityConfig.OPENTEXT_ENCODERS.contains(c.getEncoder())) { c.addDisplayComment("opentextcred"); } if (GlobalSecurityConfig.DECODABLE_ENCODERS.contains(c.getEncoder())) { c.addDisplayComment("decodablecred"); } else { c.addDisplayComment("nondecodablecred"); } return c; }) .sorted(Comparator.comparing(CredentialsCommand::getCreated)) .collect(Collectors.toList()); User userInDb = securityService.getUserByName(user.getName()); // for updates/deletes/read map.addAttribute("command", new CredentialsManagementCommand(creds)); // for new creds map.addAttribute("newCreds", new CredentialsCommand()); map.addAttribute("apps", APPS_CREDS_SETTINGS.keySet()); map.addAttribute("appsCredsSettingsJson", Util.toJson(APPS_CREDS_SETTINGS)); map.addAttribute("decodableEncoders", GlobalSecurityConfig.NONLEGACY_DECODABLE_ENCODERS); map.addAttribute("decodableEncodersJson", Util.toJson(GlobalSecurityConfig.NONLEGACY_DECODABLE_ENCODERS)); map.addAttribute("nonDecodableEncoders", GlobalSecurityConfig.NONLEGACY_NONDECODABLE_ENCODERS); map.addAttribute("nonDecodableEncodersJson", Util.toJson(GlobalSecurityConfig.NONLEGACY_NONDECODABLE_ENCODERS)); map.addAttribute("encoderAliases", ENCODER_ALIASES); map.addAttribute("encoderAliasesJson", Util.toJson(ENCODER_ALIASES)); map.addAttribute("preferredEncoderNonDecodableAllowed", securityService.getPreferredPasswordEncoder(true)); map.addAttribute("preferredEncoderDecodableOnly", securityService.getPreferredPasswordEncoder(false)); map.addAttribute("ldapAuthEnabledForUser", userInDb.isLdapAuthenticated()); map.addAttribute("adminRole", userInDb.isAdminRole()); // admin restricted, installation-wide settings if (userInDb.isAdminRole() && !map.containsAttribute("adminControls")) { map.addAttribute("adminControls", new AdminControls( securityService.checkLegacyCredsPresent(), securityService.checkOpenCredsPresent(), securityService.checkDefaultAdminCredsPresent(), settingsService.getJWTKey(), settingsService.getEncryptionPassword(), settingsService.getEncryptionSalt(), settingsService.getNonDecodablePasswordEncoder(), settingsService.getDecodablePasswordEncoder(), settingsService.getPreferNonDecodablePasswords() )); } }
Example 10
Source File: LoginFormController.java From es with Apache License 2.0 | 4 votes |
@RequestMapping(value = {"/{login:login;?.*}"}) //spring3.2.2 bug see http://jinnianshilongnian.iteye.com/blog/1831408 public String loginForm(HttpServletRequest request, ModelMap model) { //表示退出 if (!StringUtils.isEmpty(request.getParameter("logout"))) { model.addAttribute(Constants.MESSAGE, messageSource.getMessage("user.logout.success", null, null)); } //表示用户删除了 @see org.apache.shiro.web.filter.user.SysUserFilter if (!StringUtils.isEmpty(request.getParameter("notfound"))) { model.addAttribute(Constants.ERROR, messageSource.getMessage("user.notfound", null, null)); } //表示用户被管理员强制退出 if (!StringUtils.isEmpty(request.getParameter("forcelogout"))) { model.addAttribute(Constants.ERROR, messageSource.getMessage("user.forcelogout", null, null)); } //表示用户输入的验证码错误 if (!StringUtils.isEmpty(request.getParameter("jcaptchaError"))) { model.addAttribute(Constants.ERROR, messageSource.getMessage("jcaptcha.validate.error", null, null)); } //表示用户锁定了 @see org.apache.shiro.web.filter.user.SysUserFilter if (!StringUtils.isEmpty(request.getParameter("blocked"))) { User user = (User) request.getAttribute(Constants.CURRENT_USER); String reason = userStatusHistoryService.getLastReason(user); model.addAttribute(Constants.ERROR, messageSource.getMessage("user.blocked", new Object[]{reason}, null)); } if (!StringUtils.isEmpty(request.getParameter("unknown"))) { model.addAttribute(Constants.ERROR, messageSource.getMessage("user.unknown.error", null, null)); } //登录失败了 提取错误消息 Exception shiroLoginFailureEx = (Exception) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if (shiroLoginFailureEx != null) { model.addAttribute(Constants.ERROR, shiroLoginFailureEx.getMessage()); } //如果用户直接到登录页面 先退出一下 //原因:isAccessAllowed实现是subject.isAuthenticated()---->即如果用户验证通过 就允许访问 // 这样会导致登录一直死循环 Subject subject = SecurityUtils.getSubject(); if (subject != null && subject.isAuthenticated()) { subject.logout(); } //如果同时存在错误消息 和 普通消息 只保留错误消息 if (model.containsAttribute(Constants.ERROR)) { model.remove(Constants.MESSAGE); } return "front/login"; }