package eu.smartlm.abs.portal.security.login.admin; import javax.portlet.ActionResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.portlet.bind.annotation.ActionMapping; import org.springframework.web.portlet.bind.annotation.RenderMapping; import eu.smartlm.abs.portal.security.login.model.User; import eu.smartlm.abs.portal.security.login.service.LoginService; /** * Edits the parameters of a User * @author David García Pérez - CESGA */ @Controller @RequestMapping("VIEW") @SessionAttributes("user") public class EditUserController { @Autowired @Qualifier("myLoginService") private LoginService loginService; public void setLoginService(LoginService loginService) { this.loginService = loginService; } @RenderMapping(params="myaction=editUserForm") public String showEditBookForm() { return "editUserForm"; } /** * Edits an User * @param user * @param bindingResult * @param response * @param sessionStatus */ @ActionMapping(params="myaction=editUser") public void editUser(@ModelAttribute("user") User user, BindingResult bindingResult, ActionResponse response, SessionStatus sessionStatus) { if (!bindingResult.hasErrors()) { loginService.editUser(user); response.setRenderParameter("myaction", "users"); sessionStatus.setComplete(); response.removePublicRenderParameter("user"); } else { response.setRenderParameter("username", user.getUsername()); response.setRenderParameter("myaction", "editUserForm"); } } /** * User object that it is created to be passed to the jsp page * @return a User Object */ @ModelAttribute("user") public User getUser(@RequestParam String username) { return loginService.getUser(username); } }