Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Form processing the event creation page.
- *
- * @param model
- * is being passed in as well as the form information
- * @return the index page.
- */
- @RequestMapping(value = "/createEvent", method = RequestMethod.POST)
- public String createEventPost(Model model, @RequestParam("name") String name, @RequestParam("date") String dateStr,
- @RequestParam("description") String description) {
- if (name != null && name.matches(".{2,}") && description != null && description.matches(".{2,}")
- && dateStr != null && dateStr.matches("[0-9]{2}/[0-9]{2}/[0-9]{4}")) {
- String[] datePart = dateStr.split("/");
- // TODO Add 1900 as a year offset constant for the deprecated date
- // constructor
- Date eventDate = new Date(Integer.parseInt(datePart[2]) - 1900, Integer.parseInt(datePart[0]) - 1,
- Integer.parseInt(datePart[1]));
- Date currentDate = new Date(System.currentTimeMillis());
- if (eventDate.compareTo(currentDate) < 0) {
- HashMap<String, String> errors = new HashMap<String, String>();
- errors.put("date", "Error. The event's date must be after the current date.");
- model.addAttribute("errors", errors);
- return "createEvent";
- }
- // TODO Add the event creator (User)
- Event event = new Event(name, eventDate, description);
- try {
- getEventDao().addEvent(event);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "index";
- } else {
- HashMap<String, String> errors = new HashMap<String, String>();
- if (name == null || !name.matches(".{2,}")) {
- errors.put("name", "Error in the input for the event name.");
- }
- if (description == null || !description.matches(".{2,}")) {
- errors.put("description", "Error in the input for the event description.");
- }
- if (dateStr == null || !dateStr.matches("[0-9]{2}/[0-9]{2}/[0-9]{4}")) {
- errors.put("date", "Error in the input for the event's date.");
- }
- model.addAttribute("errors", errors);
- return "createEvent";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement