|
@@ -1,9 +1,11 @@
|
|
|
package pl.sudra.controller;
|
|
package pl.sudra.controller;
|
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
+import jakarta.validation.Valid;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.ServletRequestUtils;
|
|
import org.springframework.web.bind.ServletRequestUtils;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
@@ -11,9 +13,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import pl.sudra.domain.AppUser;
|
|
import pl.sudra.domain.AppUser;
|
|
|
import pl.sudra.service.AppUserService;
|
|
import pl.sudra.service.AppUserService;
|
|
|
|
|
+import pl.sudra.validator.AppUserValidator;
|
|
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
|
public class AppUserController {
|
|
public class AppUserController {
|
|
|
|
|
+ private AppUserValidator appUserValidator = new AppUserValidator();
|
|
|
|
|
|
|
|
private AppUserService appUserService;
|
|
private AppUserService appUserService;
|
|
|
|
|
|
|
@@ -34,18 +38,24 @@ public class AppUserController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/addAppUser", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/addAppUser", method = RequestMethod.POST)
|
|
|
- public String addAppUser(@ModelAttribute("appUser") AppUser appUser) {
|
|
|
|
|
|
|
+ public String addAppUser(@Valid @ModelAttribute("appUser") AppUser appUser, BindingResult result, Model model) {
|
|
|
|
|
|
|
|
System.out.println("First Name: " + appUser.getFirstName() +
|
|
System.out.println("First Name: " + appUser.getFirstName() +
|
|
|
" Last Name: " + appUser.getLastName() + " Tel.: " +
|
|
" Last Name: " + appUser.getLastName() + " Tel.: " +
|
|
|
appUser.getTelephone() + " Email: " + appUser.getEmail());
|
|
appUser.getTelephone() + " Email: " + appUser.getEmail());
|
|
|
|
|
|
|
|
- if (appUser.getId() == 0)
|
|
|
|
|
- appUserService.addAppUser(appUser);
|
|
|
|
|
- else
|
|
|
|
|
- appUserService.editAppUser(appUser);
|
|
|
|
|
|
|
+ appUserValidator.validate(appUser, result);
|
|
|
|
|
+ if (result.getErrorCount() == 0) {
|
|
|
|
|
+ if (appUser.getId() == 0)
|
|
|
|
|
+ appUserService.addAppUser(appUser);
|
|
|
|
|
+ else
|
|
|
|
|
+ appUserService.editAppUser(appUser);
|
|
|
|
|
|
|
|
- return "redirect:appUsers";
|
|
|
|
|
|
|
+ return "redirect:appUsers";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ model.addAttribute("appUserList", appUserService.listAppUser());
|
|
|
|
|
+ return "appUser";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping("/delete/{appUserId}")
|
|
@RequestMapping("/delete/{appUserId}")
|