Skip to content

Commit 7da546f

Browse files
committed
adjusting some errors in ajax
1 parent 2e32c02 commit 7da546f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

backend/src/main/java/webapp3/webapp3/controller/MonitorController.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,20 @@ public String getExercisesPageMonitor(Model model, @PathVariable int page){
261261
}
262262

263263
@PostMapping("/MONaddNewExerciseTable")
264-
public String addNewExerciseTable(Model model, @RequestParam String name, @RequestParam String description,
265-
@RequestParam List<Long> id,@RequestParam("image") MultipartFile image) throws IOException {
264+
public String addNewExerciseTable(Model model,
265+
@RequestParam(required = false) List<Long> id,
266+
@RequestParam String name,
267+
@RequestParam String description,
268+
@RequestParam("image") MultipartFile image) throws IOException {
266269
ExerciseTable exerciseTable = new ExerciseTable(name, description);
267-
List<Exercise> auxList = new ArrayList<>(id.size());
268-
for (Long l: id){
269-
auxList.add(exerServ.findById(l).orElseThrow());
270+
if (!id.isEmpty()){
271+
List<Exercise> auxList = new ArrayList<>(id.size());
272+
273+
for (Long l: id){
274+
auxList.add(exerServ.findById(l).orElseThrow());
275+
}
276+
exerciseTable.setExercises(auxList);
270277
}
271-
exerciseTable.setExercises(auxList);
272278
if (image.isEmpty()) {
273279
Resource imageNotAdded = new ClassPathResource("/sample_images/imageNotAddedActivity.jpeg");
274280
exerciseTable.setImage(BlobProxy.generateProxy(imageNotAdded.getInputStream(), imageNotAdded.contentLength()));

0 commit comments

Comments
 (0)