Skip to content

Commit 7d7ed66

Browse files
committed
completed adding a form handler method
1 parent 156fbd8 commit 7d7ed66

3 files changed

Lines changed: 86 additions & 13 deletions

File tree

Spring Boot/codingevents/.idea/workspace.xml

Lines changed: 73 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Spring Boot/codingevents/src/main/java/org/launchcode/codingevents/controllers/EventController.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.stereotype.Controller;
44
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.PostMapping;
56
import org.springframework.web.bind.annotation.RequestMapping;
67
import org.springframework.ui.Model;
8+
import org.springframework.web.bind.annotation.RequestParam;
79

810
import java.util.ArrayList;
911
import java.util.List;
@@ -12,13 +14,10 @@
1214
@RequestMapping("events")
1315
public class EventController {
1416

17+
private static List<String> events = new ArrayList<>();
18+
1519
@GetMapping
1620
public String displayAllEvents(Model model) {
17-
List<String> events = new ArrayList<>();
18-
events.add("Code With Pride");
19-
events.add("Strange Loop");
20-
events.add("Apple WWDC");
21-
events.add("SpringOne Platform");
2221
model.addAttribute("events", events);
2322
return "events/index";
2423
}
@@ -29,4 +28,11 @@ public String renderCreateEventForm() {
2928
return "events/create";
3029
}
3130

31+
// lives at /events/create
32+
@PostMapping("create")
33+
public String createEvent(@RequestParam String eventName) {
34+
events.add(eventName);
35+
return "redirect:/events";
36+
}
37+
3238
}

Spring Boot/codingevents/src/main/resources/templates/events/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<h1>All Events</h1>
1010

11+
<p th:unless="${events} and ${events.size()}">No events!</p>
12+
1113
<ul>
1214
<th:block th:each="event : ${events}">
1315
<li th:text="${event}"></li>

0 commit comments

Comments
 (0)