I am trying to understand how the binding of objects works in spring mvc. I have a Controller set up as follows, and want to have the freemarker template bind to the accessRequestBean. In the template I have '<@spring.bind "command.accessRequestBean" />' but that causes errors... How do I bind a form to a POJO?
@Controller
@PreAuthorize("isAuthenticated()")
@RequestMapping("/access")
public class RemoteVendorAccessController {
private Logger logger = Logger.getLogger(this.getClass().getName());
@Autowired
private AdDao adDao;
@Autowired
private CadaDao cadaDao;
@Autowired
private UserAccessCache userAccessCache;
private AccessRequestBean accessRequestBean;
@RequestMapping(method = RequestMethod.GET)
public String requestAccess(ModelMap map){
String username = SecurityContextHolder.getContext().getAuthentication().getName();
map.addAttribute("title", "Remote Vendor Access Request Form");
try {
AdUser user = adDao.getUserFromNt(username);
map.addAttribute("user", user);
} catch (UserDoesNotExistException e) {
String error = "Could not get user information from AD";
map.addAttribute("error", error);
logger.error(error + "[" + username + "]", e);
}
// Get users manager
AdUser manager = null;
try {
manager = adDao.getManagerFromNt(username);
map.addAttribute("manager", manager);
} catch (Exception e) {
String error = "Could not get manager information from AD";
map.addAttribute("error", error);
logger.error(error + "[" + username + "]", e);
}
return("access");
}
@RequestMapping(method = RequestMethod.POST)
public String processRequest(ModelMap map){
// Want to validate POJO bean here
return(null);
}
public AccessRequestBean getAccessRequestBean() {
return accessRequestBean;
}
public void setAccessRequestBean(AccessRequestBean accessRequestBean) {
this.accessRequestBean = accessRequestBean;
}
}