Source:
public String editProfileSubmit( @RequestParam(value = "name", required = false) String name, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "sex", required = false) String sex, @RequestParam(value = "height", required = false) Integer height, @RequestParam(value = "weight", required = false) Integer weight, Model model, HttpSession session) { MemberDao memberDao = new MemberDao(); Member member = (Member) session.getAttribute("member"); List<Team> teams = member.getTeams(); model.addAttribute("teams", teams); TournamentDao tournamentDao = new TournamentDao(); List<Tournament> tournaments = tournamentDao.getLastXTournaments(5); model.addAttribute("tournaments", tournaments); if (name != null && name.length() != 0) { if (name.length() <= 45) { member.setName(name); } else { model.addAttribute("errorMessage", NAME_ERROR_MESSAGE); return "profile"; } } if (password != null && password.length() != 0) { if (password.length() <= 45) { String genPassword = StringUtils.secureString(password); member.setPassword(genPassword); } else { model.addAttribute("errorMessage", PASSWORD_ERROR_MESSAGE); return "profile"; } } if (sex != null) { if (sex.length() == 1) { member.setSex(sex); } else { model.addAttribute("errorMessage", SEX_ERROR_MESSAGE); return "profile"; } } if (height != null) { if (height >= 0 && height <= 100) { member.setHeight(height); } else { model.addAttribute("errorMessage", HEIGHT_ERROR_MESSAGE); return "profile"; } } if (weight != null) { if (weight >= 0 && weight <= 1000) { member.setWeight(weight); } else { model.addAttribute("errorMessage", WEIGHT_ERROR_MESSAGE); return "profile"; } } memberDao.save(member); session.setAttribute("member", member); return "profile"; }

Target:
public String editProfileSubmit( @RequestParam(value = "name", required = false) String name, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "sex", required = false) String sex, @RequestParam(value = "height", required = false) Integer height, @RequestParam(value = "weight", required = false) Integer weight, Model model, HttpSession session) { MemberDao memberDao = new MemberDao(); Member member = (Member) session.getAttribute("member"); List<Team> teams = member.getTeams(); model.addAttribute("teams", teams); TournamentDao tournamentDao = new TournamentDao(); List<Tournament> tournaments = tournamentDao.getLastXTournaments(5); model.addAttribute("tournaments", tournaments); String errorMessage = ""; if (name != null && name.length() != 0) { if (name.length() <= 45) { member.setName(name); } else { errorMessage = errorMessage + " " + NAME_ERROR_MESSAGE; } } if (password != null && password.length() != 0) { if (password.length() <= 45) { String genPassword = StringUtils.secureString(password); member.setPassword(genPassword); } else { errorMessage = errorMessage + " " + PASSWORD_ERROR_MESSAGE; } } if (sex != null) { if (sex.equals("m") || sex.equals("f")) { member.setSex(sex); } else { errorMessage = errorMessage + " " + SEX_ERROR_MESSAGE; } } if (height != null) { if (height >= 0 && height <= 100) { member.setHeight(height); } else { errorMessage = errorMessage + " " + HEIGHT_ERROR_MESSAGE; } } if (weight != null) { if (weight >= 0 && weight <= 1000) { member.setWeight(weight); } else { errorMessage = errorMessage + " " + WEIGHT_ERROR_MESSAGE; } } memberDao.save(member); if (!errorMessage.equals("")) { System.out.println(errorMessage); model.addAttribute("errorMessage", errorMessage); } else { model.addAttribute("message", "Profile updated."); } session.setAttribute("member", member); return "profile"; }