0

I'm working on a Spring application for monitoring workouts. I had my workout creation working perfectly yesterday, but after a few small changes, it stopped working and displaying. I have tried reverting the changes and it still, for some reason, will not work. The page navigation still works well, I have checked my database and it is still up and active. I believe it is either an issue with my Workout Controller:

@Controller
public class WorkoutController {

@Autowired
private WorkoutService workoutService = new WorkoutService();

@RequestMapping(value = "/workout/createWorkout")
public String goToCreateWorkout(){
    return "createWorkout";
}

@RequestMapping(value = "/workout/createWorkout/workoutCreated")
public String goToWorkoutCreated(){
    return "workoutCreated";
}

@RequestMapping(value = "/workout/viewWorkout")
public String goToViewWorkout(){
    return "viewWorkout";
}

@RequestMapping(value = "/workout/deleteWorkout")
public String goToDeleteWorkout(){
    return "deleteWorkout";
}

@GetMapping("/workout/createWorkout")
public String workoutForm(Model model) {
    model.addAttribute("workout", new Workout());
    return "createWorkout";
}

@PostMapping("/workout/createWorkout")
public String submitWorkout(@ModelAttribute Workout workout,
                            HttpServletRequest request){
    Account account = (Account) request.getSession().getAttribute("loggedInUser");
    workout.setAccountName(account.getAccountName());
    workoutService.createWorkout(workout);
    return "workoutCreated";
}

@GetMapping("/workout/viewWorkout")
public String viewWorkouts(Model model){
    model.addAttribute("workouts", workoutService.getWorkouts());
    return "viewWorkout";
}
 }

Or my the form which the user submits to create the workout:

            <form action="#" th:action="@{/workout/createWorkout/workoutCreated}" th:object="${workout}" method="post">
            Workout name:<br>
            <input type="text" class="formInput" name="workout-name" size="50"
                   th:field="*{workoutName}"><br>
            <div class="divider"></div>
            Description:<br>
            <input type="text" class="formInput" name="workout-desc" size="50"
                   th:field="*{description}"><br>
            <div class="divider"></div>
            Date:<br>
            <input type="text" class="formInput" name="workout-date" size="50"
                   th:field="*{workoutDate}"><br>
            <br><br>
            <input type="submit" class="input-box">
        </form>

I'm having trouble troubleshooting this because I'm not getting any errors thrown, so I don't know where the issue is happening. Any suggestions are appreciated. Thanks.

edit: the problem is definitely that my workoutService.createWorkout(workout); is not being called. I just can't figure out why it isnt.

Polyphase29
  • 475
  • 1
  • 4
  • 17

0 Answers0