package com.vst.webapp.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.vst.Constants;
import com.vst.model.User;
import com.vst.service.UserManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import java.util.ResourceBundle;
/**
* Simple class to retrieve a list of users from the database.
* <p/>
* <p>
* <a href="UserController.java.html"><i>View Source</i></a>
* </p>
*
* @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
*/
public class UserController implements Controller {
private transient final Log log = LogFactory.getLog(UserController.class);
private UserManager mgr = null;
public void setUserManager(UserManager userManager) {
this.mgr = userManager;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'handleRequest' method...");
}
String pageNumber = request.getParameter("d-149542-p");
if (pageNumber != null) {
request.setAttribute("pageNumber", "d-149542-p=" + pageNumber);
}
if (request.getParameter("delete") != null) {
boolean hasFatalError = false;
String userId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
try {
mgr.removeUser(userId);
request.setAttribute("message", bundle.getString("user.deleted"));
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
return new ModelAndView("userList", Constants.USER_LIST, mgr.getUsers(new User()));
}
}