Hi,
I am new to Spring. I am trying to display a form for adding a user and under the form I would like to display a list of existing users. The user should not have to post the form to get the list. I want the list of users to display on the get request.
I can not figure out how to do this.
Here is my form controller...
Code:import com.edusoft.inote.domain.User; import com.edusoft.inote.service.UserService; import com.edusoft.inote.service.UserServiceImpl; @Controller @RequestMapping("/userForm") public class UserFormController{ @Autowired private UserService userService; /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); @RequestMapping(method = RequestMethod.GET) public ModelAndView show() { List users = userService.getAllUsers(); logger.info("Users size " + users.size() + "."); Map model = new HashMap(); model.put("model", users); return new ModelAndView("userForm","user",new User()); } @RequestMapping(method = RequestMethod.POST) public ModelAndView submit(Object command, @ModelAttribute("user") User user) { logger.info("Adding user name " + user.getFirstName() + "."); userService.addUser(user.getFirstName()); return new ModelAndView("userForm"); } }


Reply With Quote
