File tree Expand file tree Collapse file tree
java/org/launchcode/codingevents
resources/templates/events Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,4 +51,20 @@ public String processDeleteEventsForm(@RequestParam(required = false) int[] even
5151 return "redirect:/events" ;
5252 }
5353
54+ @ GetMapping ("edit/{eventId}" )
55+ public String displayEditForm (Model model , @ PathVariable int eventId ) {
56+ Event eventToEdit = EventData .getById (eventId );
57+ model .addAttribute ("event" , eventToEdit );
58+ String title = "Edit Event " + eventToEdit .getName () + " (ID: " + eventToEdit .getId () + ")" ;
59+ model .addAttribute ("title" , title );
60+ return "events/edit" ;
61+ }
62+
63+ @ PostMapping ("update/{eventId}" )
64+ public String processEditForm (@ ModelAttribute Event editedEvent ) {
65+ Event eventToEdit = EventData .getById (editedEvent .getId ());
66+ eventToEdit .setName (editedEvent .getName ());
67+ eventToEdit .setDescription (editedEvent .getDescription ());
68+ return "redirect:/events" ;
69+ }
5470}
Original file line number Diff line number Diff line change 11package org .launchcode .codingevents .models ;
22
3+ import jakarta .validation .constraints .Email ;
4+ import jakarta .validation .constraints .NotBlank ;
5+ import jakarta .validation .constraints .Size ;
6+
37import java .util .Objects ;
48
59public class Event {
610
711 private int id ;
812 private static int nextId = 1 ;
913
14+ @ NotBlank
15+ @ Size (min = 3 , max = 50 , message = "Name must be between 3 and 50 characters." )
1016 private String name ;
17+
18+ @ Size (max = 500 , message = "Description too long!" )
1119 private String description ;
1220
13- public Event (String name , String description ) {
21+ @ Email (message = "Invalid email. Try again." )
22+ private String contactEmail ;
23+
24+ public Event (String name , String description , String contactEmail ) {
1425 this .name = name ;
1526 this .description = description ;
27+ this .contactEmail = contactEmail ;
1628 this .id = nextId ;
1729 nextId ++;
1830 }
@@ -33,6 +45,14 @@ public void setDescription(String description) {
3345 this .description = description ;
3446 }
3547
48+ public String getContactEmail () {
49+ return contactEmail ;
50+ }
51+
52+ public void setContactEmail (String contactEmail ) {
53+ this .contactEmail = contactEmail ;
54+ }
55+
3656 public int getId () {
3757 return id ;
3858 }
Original file line number Diff line number Diff line change 1717 < input type ="text " name ="description " class ="form-control ">
1818 </ label >
1919 </ div >
20+ < div class ="form-group ">
21+ < label > Contact Email
22+ < input type ="text " name ="contactEmail " class ="form-control ">
23+ </ label >
24+ </ div >
2025 < div class ="form-group ">
2126 < input type ="submit " value ="Create " class ="btn btn-success ">
2227 </ div >
Original file line number Diff line number Diff line change 88< form method ="post ">
99
1010 < th:block th:each ="event : ${events} ">
11- < div class ="form-group ">
12- < label >
11+ < div class ="form-check ">
12+ < label class =" form-check-label " >
1313 < span th:text ="${event.name} "> </ span >
14- < input type ="checkbox " name ="eventIds " th:value ="${event.id} " class ="form-control ">
14+ < input type ="checkbox " name ="eventIds " th:value ="${event.id} " class ="form-check-input ">
1515 </ label >
1616 </ div >
1717 </ th:block >
2020</ form >
2121
2222</ body >
23- </ html >
23+ </ html >
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en " xmlns:th ="http://www.thymeleaf.org/ ">
3+ < head th:replace ="fragments :: head "> </ head >
4+ < body class ="container ">
5+
6+ < header th:replace ="fragments :: header "> </ header >
7+
8+
9+ < form method ="post " th:action ="@{/events/update/{eventId}(eventId=${event.id})} ">
10+ < input type ="hidden " th:value ="${event.id} " name ="id " />
11+
12+ < div class ="form-group " th:action ="@{/events/edit} ">
13+ < label > Name
14+ < input type ="text " name ="name " class ="form-control " th:value ="${event.name} ">
15+ </ label >
16+ </ div >
17+ < div class ="form-group ">
18+ < label > Description
19+ < input type ="text " name ="description " class ="form-control " th:value ="${event.description} ">
20+ </ label >
21+ </ div >
22+ < div class ="form-group ">
23+ < input type ="submit " value ="Update " class ="btn btn-success ">
24+ </ div >
25+ </ form >
26+ </ body >
Original file line number Diff line number Diff line change 1111 < th > ID</ th >
1212 < th > Name</ th >
1313 < th > Description</ th >
14+ < th > Contact Email</ th >
1415 </ tr >
1516 </ thead >
1617 < tr th:each ="event : ${events} ">
1718 < td th:text ="${event.id} "> </ td >
1819 < td th:text ="${event.name} "> </ td >
1920 < td th:text ="${event.description} "> </ td >
21+ < td th:text ="${event.contactEmail} "> </ td >
22+ < td >
23+ < a th:href ="@{/events/edit/{eventId}(eventId=${event.id})} "> Edit</ a >
24+ </ td >
2025 </ tr >
2126</ table >
2227
You can’t perform that action at this time.
0 commit comments