Skip to content

Commit 13699bb

Browse files
committed
completed adding a model property
1 parent 18ecdba commit 13699bb

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ public class EventController {
1919

2020
@GetMapping
2121
public String displayAllEvents(Model model) {
22+
model.addAttribute("title", "All Events");
2223
model.addAttribute("events", events);
2324
return "events/index";
2425
}
2526

2627
// lives at /events/create
2728
@GetMapping("create")
28-
public String renderCreateEventForm() {
29+
public String displayCreateEventForm(Model model) {
30+
model.addAttribute("title", "Create Event");
2931
return "events/create";
3032
}
3133

3234
// lives at /events/create
3335
@PostMapping("create")
34-
public String createEvent(@RequestParam String eventName) {
35-
events.add(new Event(eventName));
36+
public String processCreateEventForm(@RequestParam String eventName, @RequestParam String eventDescription) {
37+
events.add(new Event(eventName, eventDescription));
3638
return "redirect:/events";
3739
}
3840

Spring Boot/codingevents/src/main/java/org/launchcode/codingevents/models/Event.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
public class Event {
44

55
private String name;
6+
private String description;
67

7-
public Event(String name) {
8+
public Event(String name, String description) {
89
this.name = name;
10+
this.description = description;
911
}
1012

1113
public String getName() {
@@ -16,6 +18,14 @@ public void setName(String name) {
1618
this.name = name;
1719
}
1820

21+
public String getDescription() {
22+
return description;
23+
}
24+
25+
public void setDescription(String description) {
26+
this.description = description;
27+
}
28+
1929
@Override
2030
public String toString() {
2131
return name;

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ <h1>Create Event</h1>
99

1010
<form method="post">
1111
<div class="form-group">
12-
<label>
12+
<label>Name
1313
<input type="text" name="eventName" class="form-control">
1414
</label>
1515
</div>
16+
<div class="form-group">
17+
<label>Description
18+
<input type="text" name="eventDescription" class="form-control">
19+
</label>
20+
</div>
1621
<div class="form-group">
1722
<input type="submit" value="Create" class="btn btn-success">
1823
</div>

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ <h1>All Events</h1>
1010
<table class="table table-striped">
1111
<thead>
1212
<tr>
13-
<th>NAME</th>
13+
<th>Name</th>
14+
<th>Description</th>
1415
</tr>
1516
</thead>
1617
<tr th:each="event : ${events}">
1718
<td th:text="${event.name}"></td>
19+
<td th:text="${event.description}"></td>
1820
</tr>
1921
</table>
2022

0 commit comments

Comments
 (0)