@Controller @RequestMapping("/counter") @SessionAttributes("mycounter") public class CounterController { // Checks if there's a model attribute 'mycounter', if not create a new one. // Since 'mycounter' is labelled as session attribute it will be persisted to // HttpSession @RequestMapping(method = GET) public String get(Model model) { if(!model.containsAttribute("mycounter")) { model.addAttribute("mycounter", new MyCounter(0)); } return "counter"; } // Obtain 'mycounter' object for this user's session and increment it @RequestMapping(method = POST) public String post(@ModelAttribute("mycounter") MyCounter myCounter) { myCounter.increment(); return "redirect:/counter"; } }
@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 = "/register/create", method = RequestMethod.GET) public String registerCreatePage(Model model) { // some stuff if (!model.containsAttribute("register")) { model.addAttribute("register", new Register()); } // some more stuff }
private Map.Entry<String, AbstractIdentityProviderDefinition> evaluateIdpDiscovery( Model model, Map<String, SamlIdentityProviderDefinition> samlIdentityProviders, Map<String, AbstractXOAuthIdentityProviderDefinition> oauthIdentityProviders, Map<String, AbstractIdentityProviderDefinition> allIdentityProviders, List<String> allowedIdentityProviderKeys, Map.Entry<String, AbstractIdentityProviderDefinition> idpForRedirect, boolean discoveryEnabled, boolean discoveryPerformed, String defaultIdentityProviderName ) { if (idpForRedirect == null && (discoveryPerformed || !discoveryEnabled) && defaultIdentityProviderName != null && !model.containsAttribute("login_hint")) { //Default set, no login_hint given, discovery disabled or performed if (!OriginKeys.UAA.equals(defaultIdentityProviderName) && !OriginKeys.LDAP.equals(defaultIdentityProviderName)) { if (allIdentityProviders.containsKey(defaultIdentityProviderName)) { idpForRedirect = allIdentityProviders.entrySet().stream().filter(entry -> defaultIdentityProviderName.equals(entry.getKey())).findAny().orElse(null); } } else if (allowedIdentityProviderKeys == null || allowedIdentityProviderKeys.contains(defaultIdentityProviderName)) { UaaLoginHint loginHint = new UaaLoginHint(defaultIdentityProviderName); model.addAttribute("login_hint", loginHint.toString()); samlIdentityProviders.clear(); oauthIdentityProviders.clear(); } } return idpForRedirect; }
private String getUnauthenticatedRedirect( Model model, HttpServletRequest request, boolean discoveryEnabled, boolean discoveryPerformed ) { String formRedirectUri = request.getParameter(UaaSavedRequestAwareAuthenticationSuccessHandler.FORM_REDIRECT_PARAMETER); if (hasText(formRedirectUri)) { model.addAttribute(UaaSavedRequestAwareAuthenticationSuccessHandler.FORM_REDIRECT_PARAMETER, formRedirectUri); } boolean accountChooserEnabled = IdentityZoneHolder.get().getConfig().isAccountChooserEnabled(); boolean otherAccountSignIn = Boolean.parseBoolean(request.getParameter("otherAccountSignIn")); boolean savedAccountsEmpty = getSavedAccounts(request.getCookies(), SavedAccountOption.class).isEmpty(); if (discoveryEnabled) { if (model.containsAttribute("login_hint")) { return goToPasswordPage(null, model); } boolean accountChooserNeeded = accountChooserEnabled && !(otherAccountSignIn || savedAccountsEmpty) && !discoveryPerformed; if (accountChooserNeeded) { return "idp_discovery/account_chooser"; } if (!discoveryPerformed) { return "idp_discovery/email"; } return goToPasswordPage(request.getParameter("email"), model); } return "login"; }
.doOnSuccess(aVoid -> findModelAttributes(handlerMethod, sessionAttributesHandler).forEach(name -> { if (!bindingContext.getModel().containsAttribute(name)) { Object value = session.getRequiredAttribute(name); bindingContext.getModel().addAttribute(name, value);
@Test public void testOpenAnnouncement() { Model model = new ExtendedModelMap(); controller.open(model); assertThat(model.containsAttribute("content"), is(true)); }
@Test public void testSaveAnnouncement() { Model model = new ExtendedModelMap(); String content = "My test."; controller.save(model, content); assertThat(model.containsAttribute("success"), is(true)); assertThat(service.getOne(), is(content)); assertThat(config.getAnnouncement(), is(content)); } }
@Test public void runScriptTest() { Model model = new ExtendedModelMap(); scriptController.run("", model); assertThat((String) model.asMap().get("result"), nullValue()); String command = "print \'hello\'"; scriptController.run(command, model); assertThat(model.containsAttribute("result"), is(true)); assertThat((String) model.asMap().get("result"), containsString("hello")); scriptController.run("var a = 1", model); scriptController.run("print a", model); assertThat((String) model.asMap().get("result"), containsString("No such property")); } }
public static void addErrorMessage(String message, Model model) { if (!model.containsAttribute(ERROR_MESSAGES)) { model.addAttribute(ERROR_MESSAGES, new ArrayList<String>()); } ((List<String>) model.asMap().get(ERROR_MESSAGES)).add(message); }
public static void addInfoMessage(String message, Model model) { if (!model.containsAttribute(INFO_MESSAGES)) { model.addAttribute(INFO_MESSAGES, new ArrayList<String>()); } ((List<String>) model.asMap().get(INFO_MESSAGES)).add(message); }
@RequestMapping(method = RequestMethod.GET) public void loadSettings(Model model) { if (!model.containsAttribute("settings")) { model.addAttribute("settings", new Settings()); } model.addAttribute("settingsList", settingsService.getAllSettings(); }
@RequestMapping(value="/register", method = RequestMethod.GET) public String showRegister(Model model) { .... if (!model.containsAttribute("form")) { model.addAttribute("form", new RegistrationForm()); } ..... }
public static void addWarningMessage(String message, Model model) { if (!model.containsAttribute(WARNING_MESSAGES)) { model.addAttribute(WARNING_MESSAGES, new ArrayList<String>()); } ((List<String>) model.asMap().get(WARNING_MESSAGES)).add(message); }
public static String redirect(String destinationAction, Model model, RedirectAttributes redirectAttributes) { if (model.containsAttribute(INFO_MESSAGES)) { redirectAttributes.addFlashAttribute(INFO_MESSAGES, model.asMap().get(INFO_MESSAGES)); } if (model.containsAttribute(WARNING_MESSAGES)) { redirectAttributes.addFlashAttribute(WARNING_MESSAGES, model.asMap().get(WARNING_MESSAGES)); } if (model.containsAttribute(ERROR_MESSAGES)) { redirectAttributes.addFlashAttribute(ERROR_MESSAGES, model.asMap().get(ERROR_MESSAGES)); } return "redirect:" + destinationAction; } }
@RequestMapping(value = "/job-launcher") public void init(final Model model, @RequestParam(name = "job-name") final String jobName, @RequestParam(name = "application-instance-id") final String applicationInstanceId) { final JobLauncherModel jobLauncherModel; if (model.containsAttribute("jobLauncher")) { jobLauncherModel = (JobLauncherModel) model.asMap().get("jobLauncher"); } else { jobLauncherModel = this.jobLauncherFeService.getJobLauncherModel(jobName, applicationInstanceId); } final ApplicationContextModel applicationContextModel = this.jobLauncherFeService.getApplicationContextModel(applicationInstanceId); applicationContextModel.setJobName(jobName); model.addAttribute("jobLauncher", jobLauncherModel); model.addAttribute("applicationContextModel", applicationContextModel); }
@Override public SpringView<EditPetViewModel> bind(Model model) { model.addAttribute("races", viewModel.getRaceViewModel()); model.addAttribute("violations", viewModel.getViolations()); if (!model.containsAttribute(FORM_OBJECT)) { model.addAttribute(FORM_OBJECT, viewModel.getPet()); } return this; }
@RequestMapping(value = "/job-launcher") public void init(final Model model, @RequestParam(name = "job-name") final String jobName, @RequestParam(name = "application-instance-id") final String applicationInstanceId) { final JobLauncherModel jobLauncherModel; if (model.containsAttribute("jobLauncher")) { jobLauncherModel = (JobLauncherModel) model.asMap().get("jobLauncher"); } else { jobLauncherModel = this.jobLauncherFeService.getJobLauncherModel(jobName, applicationInstanceId); } final ApplicationContextModel applicationContextModel = this.jobLauncherFeService.getApplicationContextModel(applicationInstanceId); applicationContextModel.setJobName(jobName); model.addAttribute("jobLauncher", jobLauncherModel); model.addAttribute("applicationContextModel", applicationContextModel); }
@GetMapping(value = "/job-scheduler", params = {"init-edit-scheduler"}) public void initSchedulerUpdate( final Model model, @RequestParam(name = "job-configuration-id") final Long jobConfigurationId, @RequestParam(name = "application-instance-id") final String applicationInstanceId) { final SchedulerJobConfigurationModel schedulerConfiguration; if (model.containsAttribute("schedulerConfiguration")) { schedulerConfiguration = (SchedulerJobConfigurationModel) model.asMap().get("schedulerConfiguration"); final JobSchedulerModel schedulerModel = schedulerConfiguration.getConfig(); final String schedulerType = schedulerModel.getType(); schedulerModel.setTypeRead(new SchedulerTypeModel(SchedulerTypeModel.JobSchedulerType.valueOf(schedulerType))); } else { schedulerConfiguration = this.jobSchedulerFeService.getJobConfigurationModel(jobConfigurationId, applicationInstanceId); } model.addAttribute("schedulerConfiguration", schedulerConfiguration); model.addAttribute("modificationType", new ModificationTypeModel(ModificationTypeModel.ModificationType.UPDATE)); this.initApplicationContextModel(model, applicationInstanceId); }
@RequestMapping(value = "create", method = RequestMethod.GET) public String _showCreate(Model model, HttpServletRequest request, HttpServletResponse response) { preEdit(newModel(), model, request, response); String creteaView = showCreate(newModel(), model, request, response); if (!model.containsAttribute("data")) { model.addAttribute("data", newModel()); } if (!StringUtils.isEmpty(creteaView)) { return creteaView; } return display("edit"); }