List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.DisabilitiesFormController.java
private void fillFormIfRequired(final ExecutionYear executionYear, final Model model) { if (!model.containsAttribute("disabilitiesForm")) { model.addAttribute("disabilitiesForm", createDisabilitiesForm(executionYear, getStudent(model))); }/*www . j a v a2s.c o m*/ final DisabilitiesForm form = (DisabilitiesForm) model.asMap().get("disabilitiesForm"); form.setFirstYearRegistration(false); for (final Registration registration : getStudent(model).getRegistrationsSet()) { if (!registration.isActive()) { continue; } if (registration.getRegistrationYear() != executionYear) { continue; } form.setFirstYearRegistration(true); } }
From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.OriginInformationFormController.java
private void fillFormIfRequired(final Registration registration, Model model) { model.addAttribute("registration", registration); model.addAttribute("districtAndSubdivisionRequired", isDistrictAndSubdivisionRequired()); if (!model.containsAttribute("originInformationForm")) { model.addAttribute("originInformationForm", createOriginInformationForm(registration)); }//from w w w .ja v a2 s. co m final OriginInformationForm form = (OriginInformationForm) model.asMap().get("originInformationForm"); if (!StringUtils.isEmpty(form.getInstitutionOid())) { DomainObject institutionObject = FenixFramework.getDomainObject(form.getInstitutionOid()); if (institutionObject instanceof Unit && FenixFramework.isDomainObjectValid(institutionObject)) { form.setInstitutionName(((Unit) institutionObject).getName()); } else { form.setInstitutionName(form.getInstitutionOid()); } } }
From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.PersonalInformationFormController.java
public PersonalInformationForm fillFormIfRequired(final ExecutionYear executionYear, Model model) { Person person = getStudent(model).getPerson(); model.addAttribute("identityCardExtraDigitRequired", person.getIdDocumentType() == IDDocumentType.IDENTITY_CARD && !IdentityCardUtils.validate(person.getDocumentIdNumber(), IdentityCardUtils.getDigitControlFromPerson(person))); PersonalInformationForm form = (PersonalInformationForm) model.asMap().get("personalInformationForm"); if (form != null) { form.setDocumentIdNumber(person.getDocumentIdNumber()); form.setIdDocumentType(person.getIdDocumentType()); if (person.getIdDocumentType() == IDDocumentType.IDENTITY_CARD) { final String digitControl = IdentityCardUtils.getDigitControlFromPerson(person); if (!Strings.isNullOrEmpty(digitControl)) { form.setIdentificationDocumentSeriesNumber(digitControl); }// w w w .j av a2 s. c om } fillstaticformdata(executionYear, getStudent(model), form); model.addAttribute("personalInformationForm", form); return form; } return createPersonalInformationForm(executionYear, getStudent(model)); }
From source file:org.fenixedu.ulisboa.specifications.ui.firstTimeCandidacy.PreviousDegreeOriginInformationFormController.java
protected void fillFormIfRequired(final ExecutionYear executionYear, final Registration registration, Model model) { model.addAttribute("registration", registration); PreviousDegreeInformationForm form = (PreviousDegreeInformationForm) model.asMap() .get("previousDegreeInformationForm"); if (form == null) { form = createPreviousDegreeInformationForm(executionYear, registration); }//from w ww. ja v a2s . co m if (!StringUtils.isEmpty(form.getPrecedentInstitutionOid())) { DomainObject institutionObject = FenixFramework.getDomainObject(form.getPrecedentInstitutionOid()); if (institutionObject instanceof Unit && FenixFramework.isDomainObjectValid(institutionObject)) { form.setPrecedentInstitutionName(((Unit) institutionObject).getName()); } else { form.setPrecedentInstitutionName(form.getPrecedentInstitutionOid()); } } model.addAttribute("previousDegreeInformationForm", form); }
From source file:org.jasig.portlet.announcements.mvc.portlet.display.AnnouncementsViewController.java
/** * Main method of this display controller. Calculates which topics should be shown to this user * and which announcements to show from those topics. *///ww w . ja v a 2 s . com @SuppressWarnings("unchecked") @RenderMapping() public String mainView(Model model, RenderRequest request, @RequestParam(value = "from", required = false) Integer from, @RequestParam(value = "to", required = false) Integer to) throws PortletException { if (from == null || to == null) { from = 0; to = (Integer) model.asMap().get("increment"); } final PortletPreferences prefs = request.getPreferences(); List[] lists = getLists(request); List<Announcement> announcements = lists[0]; List<Announcement> emergencyAnnouncements = lists[1]; // sort the list (since they are not sorted from the database) Comparator<Announcement> sortStrategy = AnnouncementSortStrategy .getStrategy(prefs.getValue(PREFERENCE_SORT_STRATEGY, DEFAULT_SORT_STRATEGY)); Collections.sort(announcements, sortStrategy); Collections.sort(emergencyAnnouncements, sortStrategy); // create a shortened list final Boolean useScrollingDisplay = (Boolean) model.asMap().get("useScrollingDisplay"); final List<Announcement> announcementsShort = useScrollingDisplay ? announcements : paginateAnnouncements(announcements, from, to, model); // Disable the edit link where appropriate Boolean disableEdit = Boolean.valueOf(prefs.getValue(PREFERENCE_DISABLE_EDIT, "false")); model.addAttribute("disableEdit", disableEdit); model.addAttribute("from", new Integer(from)); model.addAttribute("to", new Integer(to)); model.addAttribute("hasMore", (!useScrollingDisplay && announcements.size() > to)); model.addAttribute("announcements", announcementsShort); model.addAttribute("emergency", emergencyAnnouncements); model.addAttribute("hideAbstract", Boolean.valueOf(prefs.getValue(PREFERENCE_HIDE_ABSTRACT, "false"))); return viewNameSelector.select(request, "displayAnnouncements"); }
From source file:org.jasig.portlet.newsreader.mvc.portlet.reader.NewsController.java
@RenderMapping(params = "action=fullStory") public ModelAndView fullStory(@RequestParam Long activeFeed, @RequestParam int itemIndex, @RequestParam int page, RenderRequest request, RenderResponse response, Model model) throws Exception { log.trace("fullStory (NewsController)"); //Security check that the feed belongs to the user String setName = request.getPreferences().getValue("newsSetName", "default"); NewsSet set = setCreationService.getNewsSet(setName, request); List<NewsConfiguration> feeds = new ArrayList<NewsConfiguration>(); feeds.addAll(set.getNewsConfigurations()); Collections.sort(feeds);//from w w w .j ava2 s. co m JSONArray jsonFeeds = new JSONArray(); List<String> knownFeeds = new ArrayList<String>(); for (NewsConfiguration feed : feeds) { if (feed.isDisplayed()) { JSONObject jsonFeed = new JSONObject(); jsonFeed.put("id", feed.getId()); jsonFeed.put("name", feed.getNewsDefinition().getName()); jsonFeeds.add(jsonFeed); knownFeeds.add(String.valueOf(feed.getId())); } } log.debug("Known feeds: " + knownFeeds.toString()); model.addAttribute("feeds", jsonFeeds); if (!knownFeeds.contains(activeFeed.toString())) { activeFeed = null; model.addAttribute("message", "Not allowed."); log.debug("Not allowd."); } model.addAttribute("activeFeed", activeFeed); NewsConfiguration feedConfig = newsStore.getNewsConfiguration(activeFeed); log.debug("On render Active feed is " + feedConfig.getId()); try { // get an instance of the adapter for this feed INewsAdapter adapter = (INewsAdapter) applicationContext .getBean(feedConfig.getNewsDefinition().getClassName()); // retrieve the feed from this adaptor NewsFeed sharedFeed = adapter.getSyndFeed(feedConfig, page); if (sharedFeed != null) { NewsFeedItem item = sharedFeed.getEntries().get(itemIndex); model.addAttribute("storyTitle", item.getTitle()); FullStory fullStory = item.getFullStory(); model.addAttribute("fullStory", fullStory.getFullStoryText()); } else { log.warn("Failed to get feed from adapter."); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } PortletPreferences prefs = request.getPreferences(); model.addAttribute("feedView", prefs.getValue("feedView", "select")); } catch (NoSuchBeanDefinitionException ex) { log.error("News class instance could not be found: " + ex.getMessage()); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } catch (NewsException ex) { log.warn(ex); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } catch (Exception ex) { log.error(ex); model.addAttribute("message", "The news \"" + feedConfig.getNewsDefinition().getName() + "\" is currently unavailable."); } String etag = String.valueOf(model.hashCode()); String requestEtag = request.getETag(); // if the request ETag matches the hash for this response, send back // an empty response indicating that cached content should be used if (request.getETag() != null && etag.equals(requestEtag)) { response.getCacheControl().setExpirationTime(1); response.getCacheControl().setUseCachedContent(true); // returning null appears to cause the response to be committed // before returning to the portal, so just use an empty view return new ModelAndView("empty", Collections.<String, String>emptyMap()); } // create new content with new validation tag response.getCacheControl().setETag(etag); response.getCacheControl().setExpirationTime(1); String viewName = viewResolver.getFullStoryView(request); return new ModelAndView(viewName, model.asMap()); }
From source file:org.kuali.mobility.writer.controllers.WriterEditArticleController.java
@RequestMapping(value = "/mediaUpload", method = RequestMethod.POST) public ResponseEntity<String> mediaUpload(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile mediaFile, @RequestParam(value = "mediaType") int mediaType, @RequestParam(value = "articleId", required = false) long articleId, Model uiModel) { Media media = service.uploadMediaData(mediaFile, mediaType); if (media == null) { return new ResponseEntity<String>(HttpStatus.METHOD_FAILURE); } else {//from w ww . ja va 2 s.co m Article article = (Article) uiModel.asMap().get("article"); boolean hadArticle = true; if (article == null) { article = this.service.getArticle(articleId); hadArticle = false; } article = service.updateMedia(article, media); if (hadArticle) { uiModel.addAttribute("article", article); } } return new ResponseEntity<String>(HttpStatus.OK); }
From source file:org.opens.tgol.controller.AuditResultController.java
/** * This method prepares the data to be displayed in the sort * (referential, theme, result types) console of the result page. * //w ww.j av a 2s . c o m * @param webResourceId * @param displayScope * @param auditResultSortCommand * @param model */ private void prepareDataForSortConsole(Long webResourceId, String displayScope, AuditResultSortCommand auditResultSortCommand, Model model) { // Meta-statistics have been added to the method previously String referentialParameter = ((AuditStatistics) model.asMap().get(TgolKeyStore.STATISTICS_KEY)) .getParametersMap().get(referentialCode); AuditResultSortCommand asuc; List<FormField> formFieldList; if (auditResultSortCommand == null) { formFieldList = AuditResultSortCommandFactory.getInstance() .getFormFieldBuilderCopy(referentialParameter, sortFormFieldBuilderList); asuc = AuditResultSortCommandFactory.getInstance().getInitialisedAuditResultSortCommand(webResourceId, displayScope, isCriterionViewAccessible(webResourceId, referentialParameter), formFieldList); } else { formFieldList = AuditResultSortCommandFactory.getInstance().getFormFieldBuilderCopy( referentialParameter, sortFormFieldBuilderList, auditResultSortCommand); asuc = auditResultSortCommand; } model.addAttribute(TgolKeyStore.AUDIT_RESULT_SORT_FIELD_LIST_KEY, formFieldList); model.addAttribute(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY, asuc); }
From source file:org.opens.tgol.controller.AuditResultController.java
/** * This methods handles audit data in case of page type audit * /*w ww. j av a 2 s.c o m*/ * @param page * @param audit * @param model * @param displayScope * @return * @throws IOException */ private String prepareSuccessfullPageData(Page page, Audit audit, Model model, String displayScope) { Contract contract = retrieveContractFromAudit(audit); if (!audit.getStatus().equals(AuditStatus.COMPLETED)) { return prepareFailedAuditData(audit, model); } model.addAttribute(TgolKeyStore.STATUS_KEY, computeAuditStatus(audit)); model.addAttribute(TgolKeyStore.RESULT_ACTION_LIST_KEY, actionHandler.getActionList("EXPORT")); // Attributes for breadcrumb model.addAttribute(TgolKeyStore.CONTRACT_ID_KEY, contract.getId()); model.addAttribute(TgolKeyStore.CONTRACT_NAME_KEY, contract.getLabel()); model.addAttribute(TgolKeyStore.AUDIT_ID_KEY, audit.getId()); // Add a boolean used to display the breadcrumb. model.addAttribute(TgolKeyStore.AUTHORIZED_SCOPE_FOR_PAGE_LIST, isAuthorizedScopeForPageList(audit)); // Add a command to relaunch the audit from the result page model.addAttribute(TgolKeyStore.AUDIT_SET_UP_COMMAND_KEY, AuditSetUpCommandFactory.getInstance().getPageAuditSetUpCommand(contract, page.getURL(), getParameterDataService().getParameterSetFromAudit(audit))); if (StringUtils.equalsIgnoreCase(displayScope, TgolKeyStore.TEST_DISPLAY_SCOPE_VALUE)) { AuditResultSortCommand asuc = ((AuditResultSortCommand) model.asMap() .get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY)); model.addAttribute(TgolKeyStore.TEST_RESULT_LIST_KEY, TestResultFactory.getInstance().getTestResultSortedByThemeMap(page, getPageScope(), asuc.getSortOptionMap().get(themeSortKey).toString(), getTestResultSortSelection(asuc))); return TgolKeyStore.RESULT_PAGE_VIEW_NAME; } else { AuditResultSortCommand asuc = ((AuditResultSortCommand) model.asMap() .get(TgolKeyStore.AUDIT_RESULT_SORT_COMMAND_KEY)); model.addAttribute(TgolKeyStore.CRITERION_RESULT_LIST_KEY, CriterionResultFactory.getInstance().getCriterionResultSortedByThemeMap(page, asuc.getSortOptionMap().get(themeSortKey).toString(), getTestResultSortSelection(asuc))); return TgolKeyStore.RESULT_PAGE_BY_CRITERION_VIEW_NAME; } }
From source file:org.opens.tgol.controller.ForgottenOrChangePasswordController.java
/** * //from w w w . j a va2s. co m * @param email * @param token * @param model * @param request * @return */ private String displayChangePasswordView(String id, String token, Model model, HttpServletRequest request) { Long userId; try { userId = Long.valueOf(id); } catch (NumberFormatException nfe) { throw new ForbiddenUserException(); } if (StringUtils.isBlank(token)) { return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME; } User currentUser = getCurrentUser(); User user; // if the change password request comes from an authentied user or from // an admin if (token.equalsIgnoreCase(AUTHENTICATED_KEY)) { if (currentUser == null || (!currentUser.getId().equals(userId) && !currentUser.getRole().getRoleName().equals(ROLE_ADMIN_NAME_KEY)) || forbiddenUserList.contains(currentUser.getEmail1())) { return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME; } else { if (!currentUser.getId().equals(userId)) { user = getUserDataService().read(userId); } else { user = currentUser; } } // the request is submitted through an unauthentified user and the token // has to be checked. } else { user = getUserDataService().read(userId); try { // if the token is invalid if (!tokenManager.checkUserToken(user.getEmail1(), token)) { model.addAttribute(TgolKeyStore.INVALID_CHANGE_PASSWORD_URL_KEY, true); return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME; } else { // if the token is valid but the request comes from the // form submission with success Object passwordModified = model.asMap().get(TgolKeyStore.PASSWORD_MODIFIED_KEY); if (passwordModified instanceof Boolean && (Boolean) passwordModified) { tokenManager.setTokenUsed(token); return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME; } } } catch (ArrayIndexOutOfBoundsException aioobe) { model.addAttribute(TgolKeyStore.INVALID_CHANGE_PASSWORD_URL_KEY, true); return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME; } } if (user == null) { return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME; } ChangePasswordCommand cpc = new ChangePasswordCommand(); model.addAttribute(TgolKeyStore.CHANGE_PASSWORD_COMMAND_KEY, cpc); model.addAttribute(TgolKeyStore.USER_NAME_KEY, user.getEmail1()); request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, user.getId()); return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME; }