List of usage examples for org.springframework.ui ModelMap containsAttribute
public boolean containsAttribute(String attributeName)
From source file:com.trenako.web.controllers.ReviewsControllerTests.java
@Test public void shouldRenderFormsForReviewsCreation() { String slug = "acme-123456"; ModelMap model = new ModelMap(); when(mockRsService.findBySlug(eq(slug))).thenReturn(rollingStock()); when(mockUserContext.getCurrentUser()).thenReturn(new AccountDetails(author())); String viewName = controller.newReview(slug, model); assertEquals("review/new", viewName); assertTrue("Rolling stock not found", model.containsAttribute("rs")); assertEquals(rollingStock(), (RollingStock) model.get("rs")); assertTrue("Review form not found", model.containsAttribute("reviewForm")); ReviewForm reviewForm = (ReviewForm) model.get("reviewForm"); assertEquals(rollingStock().getSlug(), reviewForm.getRsSlug()); assertEquals(rollingStock().getLabel(), reviewForm.getRsLabel()); assertEquals(author().getSlug(), reviewForm.getReview().getAuthor()); }
From source file:com.trenako.web.controllers.RollingStocksControllerTests.java
@Test public void shouldShowRollingStockViewsForAuthenticatedUsers() { String slug = "acme-123456"; RollingStockView value = new RollingStockView(rollingStock(), null, null, null); when(service.findRollingStockView(eq(slug), eq(loggedUser()))).thenReturn(value); ModelMap model = new ExtendedModelMap(); String viewName = controller.show(slug, model); assertEquals("rollingstock/show", viewName); assertTrue(model.containsAttribute("result")); assertEquals(value, model.get("result")); CommentForm commentForm = (CommentForm) model.get("commentForm"); assertNotNull("Comment is null", commentForm); assertEquals("bob", commentForm.getComment().getAuthor()); assertEquals("acme-123456", commentForm.getRsSlug()); assertEquals("ACME 123456", commentForm.getRsLabel()); }
From source file:com.trenako.web.controllers.RollingStocksControllerTests.java
@Test public void shouldRenderRollingStockViews() { String slug = "acme-123456"; RollingStockView value = new RollingStockView(rollingStock(), null, null, null); when(service.findRollingStockView(eq(slug), (Account) isNull())).thenReturn(value); ModelMap model = new ExtendedModelMap(); controller.setUserContext(null);/*from w w w.j av a2 s . c o m*/ String viewName = controller.show(slug, model); assertEquals("rollingstock/show", viewName); assertTrue(model.containsAttribute("result")); assertEquals(value, model.get("result")); CommentForm commentForm = (CommentForm) model.get("commentForm"); assertNull("Comment is not null", commentForm); }
From source file:com.trenako.web.controllers.ReviewsControllerTests.java
@Test public void shouldRedirectAfterValidationErrorsDuringReviewsPosting() { String slug = "acme-123456"; ModelMap model = new ModelMap(); when(mockResult.hasErrors()).thenReturn(true); when(mockRsService.findBySlug(eq(slug))).thenReturn(rollingStock()); when(mockUserContext.getCurrentUser()).thenReturn(new AccountDetails(author())); String viewName = controller.postReview(postedForm(), mockResult, model, mockRedirectAtts); assertEquals("review/new", viewName); assertTrue("Review not found", model.containsAttribute("reviewForm")); ReviewForm form = (ReviewForm) model.get("reviewForm"); assertEquals(postedForm(), form);// w w w . j a v a 2s. c o m verify(mockService, times(0)).postReview(isA(RollingStock.class), isA(Review.class)); }
From source file:com.virtusa.akura.staff.controller.StaffExtraCurricularController.java
/** * Returns staff extra curricular main page which has staff club & society, staff sport, staff seminar and * staff external activity information.//w ww . java2s . c o m * * @param modelMap - holds ModelMap object * @param request - holds HttpServletRequest object * @return view page for staff extra curricular. * @throws AkuraAppException - throw a detailed exception when view */ @RequestMapping(value = REQ_MAP_VALUE_VIEW, method = RequestMethod.GET) public String viewStaffExtraCurricularPage(ModelMap modelMap, HttpServletRequest request) throws AkuraAppException { Staff obj; int staffId = getSessionStaffId(request.getSession()); obj = (Staff) staffService.viewStaff(staffId); Date departureDate = staffService.findStaff(obj.getStaffId()).getDateOfDeparture(); modelMap.addAttribute(DEPARTURE_DATE, departureDate); if (!modelMap.containsAttribute(MODEL_ATT_STAFFCLUBSOCIETY)) { modelMap.addAttribute(MODEL_ATT_STAFFCLUBSOCIETY, new StaffClubSociety()); } if (!modelMap.containsAttribute(MODEL_ATT_STAFFEXTERNALACTIVITY)) { modelMap.addAttribute(MODEL_ATT_STAFFEXTERNALACTIVITY, new StaffExternalActivity()); } if (!modelMap.containsAttribute(MODEL_ATT_STAFFSPORT)) { modelMap.addAttribute(MODEL_ATT_STAFFSPORT, new StaffSport()); } if (!modelMap.containsAttribute(MODEL_ATT_STAFFSEMINAR)) { modelMap.addAttribute(MODEL_ATT_STAFFSEMINAR, new StaffSeminar()); } return populateDataForSelectedYear(modelMap, request); }
From source file:org.motechproject.server.omod.web.controller.EditPatientControllerTest.java
public void testEditPatient() { Integer patientId = 1, communityId = 11112, motherId = 2; String firstName = "FirstName", middleName = "MiddleName", lastName = "LastName", prefName = "PrefName"; String region = "Region", district = "District", address = "Address", nhis = "1234DEF"; String phoneNumber = "0123456789"; Boolean birthDateEst = true, enroll = true, consent = true, insured = true; Date date = new Date(); Gender sex = Gender.FEMALE;/*from ww w. jav a 2s . c o m*/ ContactNumberType phoneType = ContactNumberType.PERSONAL; MediaType mediaType = MediaType.TEXT; String language = "en"; DayOfWeek dayOfWeek = DayOfWeek.FRIDAY; WebPatient patient = new WebPatient(); patient.setId(patientId); patient.setFirstName(firstName); patient.setMiddleName(middleName); patient.setLastName(lastName); patient.setPrefName(prefName); patient.setBirthDate(date); patient.setBirthDateEst(birthDateEst); patient.setSex(sex); patient.setInsured(insured); patient.setNhis(nhis); patient.setNhisExpDate(date); patient.setMotherMotechId(motherId); patient.setRegion(region); patient.setDistrict(district); patient.setCommunityId(communityId); patient.setAddress(address); patient.setPhoneNumber(phoneNumber); patient.setPhoneType(phoneType); patient.setMediaType(mediaType); patient.setLanguage(language); patient.setDueDate(date); patient.setEnroll(enroll); patient.setConsent(consent); patient.setDayOfWeek(dayOfWeek); patient.setTimeOfDay(date); patient.setFacility(11117); Errors errors = new BeanPropertyBindingResult(patient, "patient"); ModelMap model = new ModelMap(); Patient openmrsPatient = new Patient(1); Patient motherPatient = new Patient(2); Community community = new Community(); expect(registrarBean.getPatientById(patientId)).andReturn(openmrsPatient); expect(openmrsBean.getPatientByMotechId(motherId.toString())).andReturn(motherPatient); expect(registrarBean.getCommunityById(communityId)).andReturn(community); Facility facility = new Facility(); facility.setFacilityId(11117); expect(registrarBean.getFacilityById(facility.getFacilityId())).andReturn(facility); JSONLocationSerializer.populateJavascriptMaps(model, patient.getPreferredLocation()); expectLastCall(); registrarBean.editPatient(openmrsPatient, firstName, middleName, lastName, prefName, date, birthDateEst, sex, insured, nhis, date, motherPatient, community, address, phoneNumber, date, enroll, consent, phoneType, mediaType, language, dayOfWeek, date, facility); status.setComplete(); replay(registrarBean, status, contextService, motechService, openmrsBean, JSONLocationSerializer); controller.submitForm(patient, errors, model, status); verify(registrarBean, status, contextService, motechService, openmrsBean, JSONLocationSerializer); assertTrue("Missing success message in model", model.containsAttribute("successMsg")); }
From source file:com.ace.console.controller.LoginFormController.java
@RequestMapping(value = { "/{login:login;?.*}" }) public String loginForm(@CurrentUser User user, HttpServletRequest request, ModelMap model) { ////from ww w . j av a 2 s .c om 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)); // } // ???? Exception shiroLoginFailureEx = (Exception) request .getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME); if (shiroLoginFailureEx != null) { try { model.addAttribute(Constants.ERROR, messageSource.getMessage(shiroLoginFailureEx.getMessage(), null, null)); } catch (Exception ex) { logger.error("user login error : ", ex); model.addAttribute(Constants.ERROR, messageSource.getMessage("user.unknown.error", null, null)); } } //? //isAccessAllowedsubject.isAuthenticated()---->?? ? // Subject subject = SecurityUtils.getSubject(); if (subject != null && subject.isAuthenticated()) { subject.logout(); } //?? ? ??? if (model.containsAttribute(Constants.ERROR)) { model.remove(Constants.MESSAGE); } return "/login"; }
From source file:cz.strmik.cmmitool.web.controller.OrganizationController.java
@RequestMapping(method = RequestMethod.GET, value = "/edit-{orgId}.do") public String setupFormEdit(@PathVariable("orgId") Long orgId, ModelMap model) { if (!model.containsAttribute("org")) { Organization org = organizationDao.read(orgId); model.addAttribute("org", org); model.addAttribute("create", Boolean.FALSE); }//from ww w . j ava 2 s . c o m return ORG_FORM; }
From source file:cz.strmik.cmmitool.web.controller.OrganizationController.java
@RequestMapping(method = RequestMethod.GET, value = "/add.do") public String setupFormAdd(ModelMap model) { if (!model.containsAttribute("org")) { Organization org = new Organization(); org.setActive(true);// w w w . ja va2s.co m model.addAttribute("org", org); model.addAttribute("create", Boolean.TRUE); } return ORG_FORM; }
From source file:cz.strmik.cmmitool.web.controller.UsersController.java
@RequestMapping(method = RequestMethod.GET, value = "/edit-{userId}.do") public String setupFormEdit(@PathVariable("userId") String userId, ModelMap model) { if (!model.containsAttribute("user")) { User user = userDao.findUser(userId); model.addAttribute("user", user); }//from www . jav a2s . c o m return USER_FORM; }