List of usage examples for org.springframework.validation FieldError getDefaultMessage
@Override
@Nullable
public String getDefaultMessage()
From source file:sg.ncl.MainController.java
private String buildErrorMessage(BindingResult binding) { StringBuilder message = new StringBuilder(); message.append(TAG_ERRORS);/* w ww . j a v a 2 s . c o m*/ message.append(TAG_UL); for (ObjectError objectError : binding.getAllErrors()) { FieldError fieldError = (FieldError) objectError; message.append(TAG_LI); switch (fieldError.getField()) { case ORGANISATION_TYPE: message.append("Organisation Type "); message.append(fieldError.getDefaultMessage()); break; case ORGANISATION_NAME: message.append("Organisation Name "); message.append(fieldError.getDefaultMessage()); break; case KEY_PROJECT_NAME: message.append("Project Name "); message.append(fieldError.getDefaultMessage()); break; case KEY_OWNER: message.append("Owner "); message.append(fieldError.getDefaultMessage()); break; case KEY_DATE_CREATED: message.append("Date Created "); message.append(fieldError.getDefaultMessage()); break; case "month": message.append("Month "); message.append(fieldError.getDefaultMessage()); break; default: message.append(fieldError.getField()); message.append(TAG_SPACE); message.append(fieldError.getDefaultMessage()); } message.append(TAG_LI_CLOSE); } message.append(TAG_UL_CLOSE); return message.toString(); }
From source file:sg.ncl.MainController.java
@PostMapping("/admin/statistics") public String adminUsageStatisticsQuery(@Valid @ModelAttribute("query") ProjectUsageQuery query, BindingResult result, RedirectAttributes attributes, HttpSession session) { if (!validateIfAdmin(session)) { return NO_PERMISSION_PAGE; }//from ww w .jav a2 s . co m List<ProjectDetails> newProjects = new ArrayList<>(); List<ProjectDetails> activeProjects = new ArrayList<>(); List<ProjectDetails> inactiveProjects = new ArrayList<>(); List<ProjectDetails> stoppedProjects = new ArrayList<>(); List<String> months = new ArrayList<>(); Map<String, MonthlyUtilization> utilizationMap = new HashMap<>(); Map<String, Integer> statsCategoryMap = new HashMap<>(); Map<String, Integer> statsAcademicMap = new HashMap<>(); int totalCategoryUsage = 0; int totalAcademicUsage = 0; if (result.hasErrors()) { StringBuilder message = new StringBuilder(); message.append(TAG_ERRORS); message.append(TAG_UL); for (ObjectError objectError : result.getAllErrors()) { FieldError fieldError = (FieldError) objectError; message.append(TAG_LI); message.append(fieldError.getField()); message.append(TAG_SPACE); message.append(fieldError.getDefaultMessage()); message.append(TAG_LI_CLOSE); } message.append(TAG_UL_CLOSE); attributes.addFlashAttribute(MESSAGE, message.toString()); } else { DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendPattern("MMM-yyyy").toFormatter(); YearMonth m_s = YearMonth.parse(query.getStart(), formatter); YearMonth m_e = YearMonth.parse(query.getEnd(), formatter); YearMonth counter = m_s; while (!counter.isAfter(m_e)) { String monthYear = counter.format(formatter); utilizationMap.put(monthYear, new MonthlyUtilization(monthYear)); months.add(monthYear); counter = counter.plusMonths(1); } List<ProjectDetails> projectsList = getProjects(); for (ProjectDetails project : projectsList) { // compute active and inactive projects differentiateProjects(newProjects, activeProjects, inactiveProjects, stoppedProjects, m_s, m_e, project); // monthly utilisation computeMonthlyUtilisation(utilizationMap, formatter, m_s, m_e, project); // usage statistics by category totalCategoryUsage += getCategoryUsage(statsCategoryMap, m_s, m_e, project); // usage statistics by academic institutes totalAcademicUsage += getAcademicUsage(statsAcademicMap, m_s, m_e, project); } } attributes.addFlashAttribute(KEY_QUERY, query); attributes.addFlashAttribute("newProjects", newProjects); attributes.addFlashAttribute("activeProjects", activeProjects); attributes.addFlashAttribute("inactiveProjects", inactiveProjects); attributes.addFlashAttribute("stoppedProjects", stoppedProjects); attributes.addFlashAttribute("months", months); attributes.addFlashAttribute("utilization", utilizationMap); attributes.addFlashAttribute("statsCategory", statsCategoryMap); attributes.addFlashAttribute("totalCategoryUsage", totalCategoryUsage); attributes.addFlashAttribute("statsAcademic", statsAcademicMap); attributes.addFlashAttribute("totalAcademicUsage", totalAcademicUsage); return "redirect:/admin/statistics"; }