Skip to content
Snippets Groups Projects
Commit 230155df authored by Rhys Evans's avatar Rhys Evans
Browse files

created basic thymeleaf form with basic get/postMapping functionality

parent 6283046d
No related branches found
No related tags found
1 merge request!13Resolve "As a user I want to be able submit a form about a specific landmark to add to the trail"
......@@ -28,6 +28,9 @@ dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-validation'
// implementation 'org.springframework.boot:spring-boot-starter-jdbc'
// implementation 'org.mariadb.jdbc:mariadb-java-client:2.1.2'
}
tasks.named('bootBuildImage') {
......
package Team5.SmartTowns.Landmarks;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
public class Landmarks {
private String landmarkName;
private String landmarkDescription;
......@@ -7,12 +10,17 @@ public class Landmarks {
private int trailID;
public Landmarks(){
this.landmarkName ="";
this.landmarkDescription ="";
this.landmarkLocation ="";
this.trailID =0;
}
public Landmarks(String landmarkName, String landmarkDescription, String landmarkLocation, int trailID) {
this.landmarkName = landmarkName;
this.landmarkDescription = landmarkDescription;
this.landmarkLocation = landmarkLocation;
this.trailID = trailID;
}
}
......@@ -9,8 +9,22 @@ public class LandmarksArray {
LandmarksArray() {
landmarksList = new ArrayList<>(); //ArrayList is mutable
landmarksList.addAll(
List.of(
new Landmarks("park","desc","loc",2)
)
);
}
// public static UserArray getInstance() {
// if (singleton == null) {
// singleton = new UserArray();
//
// }
// return singleton;
// }
}
package Team5.SmartTowns.Landmarks;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;
//import jakarta.validation.Valid;
@Controller
public class LandmarksController {
@GetMapping("/landmarkSubmission")
public ModelAndView landmarkSubmission(){
ModelAndView modelAndView = new ModelAndView("Landmarks/LandmarkFormTh.html");
modelAndView.addAllObjects("Landmarks", new Landmarks());
return modelAndView;
ModelAndView modelAndView1 = new ModelAndView("LandmarkFormTh.html");
modelAndView1.addObject("landmarkData", new Landmarks());
return modelAndView1;
}
@PostMapping("/landmarkSub")
public ModelAndView landmarkSent( @ModelAttribute("landmarkData") Landmarks landmarks ) {
// LandmarksArray userArray = LandmarksArray.getInstance();
// Landmarks newUserSubmission = new Landmarks(landmarkData.getFormUsername(),userSubmission.getFormEmail(),
// userSubmission.getFormPark(), userSubmission.getFormDescription(),userSubmission.getFormCafe(), userSubmission.getFormToilets());
// userArray.addUserSubmission(newUserSubmission);
// System.out.println(userArray.getFormItems());
//
ModelAndView modelAndView = new ModelAndView("redirect:/test.html");
return modelAndView;
}
// @PostMapping("/landmarkSubmission")
// public ModelAndView landmarkSubmission( Landmarks landmarks){
// System.out.println(landmarks);
// ModelAndView modelAndView = new ModelAndView("redirect:/thankyou.html");
//
// return modelAndView;
//
// }
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Landmark Sign Up</title>
</head>
<body>
<main>
<form action="/landmarkSub" id="landmarkSubmission" name="landmarkSubmission" method="post" th:object="${landmarkData}">
<label>Business Name:
<input type="text" th:field="*{landmarkName}">
</label><br>
<label>Please Describe Your Business:<br>
<textarea th:field="*{landmarkDescription}" rows="6" cols="80"></textarea>
</label><br>
<label>Your town/city:
<input type="text" th:field="*{landmarkName}">
</label><br>
<label>Trail:
<input type="text" th:field="*{trailID}">
</label><br>
<input type="submit">
</form>
</main>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Landmark Sign Up</title>
</head>
<body>
<main>
<form action="/LandmarkSubmission" name="landmarkSubmission">
</form>
</main>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment