View Javadoc

1   package org.appfuse.webapp.controller;
2   
3   import org.appfuse.Constants;
4   import org.appfuse.dao.SearchException;
5   import org.appfuse.service.UserManager;
6   import org.springframework.beans.factory.annotation.Autowired;
7   import org.springframework.stereotype.Controller;
8   import org.springframework.ui.ExtendedModelMap;
9   import org.springframework.ui.Model;
10  import org.springframework.web.bind.annotation.RequestMapping;
11  import org.springframework.web.bind.annotation.RequestMethod;
12  import org.springframework.web.bind.annotation.RequestParam;
13  import org.springframework.web.servlet.ModelAndView;
14  
15  
16  /**
17   * Simple class to retrieve a list of users from the database.
18   * <p/>
19   * <p>
20   * <a href="UserController.java.html"><i>View Source</i></a>
21   * </p>
22   *
23   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
24   */
25  @Controller
26  @RequestMapping("/admin/users*")
27  public class UserController {
28      private UserManager userManager = null;
29  
30      @Autowired
31      public void setUserManager(UserManager userManager) {
32          this.userManager = userManager;
33      }
34  
35      @RequestMapping(method = RequestMethod.GET)
36      public ModelAndView handleRequest(@RequestParam(required = false, value = "q") String query) throws Exception {
37          Model model = new ExtendedModelMap();
38          try {
39              model.addAttribute(Constants.USER_LIST, userManager.search(query));
40          } catch (SearchException se) {
41              model.addAttribute("searchError", se.getMessage());
42              model.addAttribute(userManager.getUsers());
43          }
44          return new ModelAndView("admin/userList", model.asMap());
45      }
46  }