I have a class to store several command objects:
I have an annotated form controller:Code:public class FormCommandMap { private HashMap<String, Object> commandMap; public FormCommandMap() { commandMap = new HashMap<String, Object>(); } public void addCommand(String key, Object command) { commandMap.put(key, command); } public void removeCommand(String key) { commandMap.remove(key); } public Object getCommand(String key) { return commandMap.get(key); } public void setCommandMap(HashMap<String, Object> hashMap) { commandMap = hashMap; } public HashMap<String, Object> getCommandMap() { return commandMap; } } // End CLass: FormCommandMap
And I have my view (cms_add_page.ftl):Code:@RequestMapping(value = "/cms/add/page", method = RequestMethod.GET) public ModelAndView get() { FormCommandMap fcm = new FormCommandMap(); Page targetPage = new Page(); PageController targetController = new PageController(); PageProperties targetProperties = new PageProperties(); fcm.addCommand("target_page", targetPage); fcm.addCommand("target_controller", targetController); fcm.addCommand("target_properties", targetProperties); ModelMap mmap = new ModelMap(); mmap.addAttribute("form_command_map", fcm); return new ModelAndView("cms_add_page", mmap); } @RequestMapping(value = "/cms/add/page", method = RequestMethod.POST) public ModelAndView post(@ModelAttribute("form_command_map") FormCommandMap form_command_map, BindingResult result, SessionStatus status) { Page targetPage = (Page) form_command_map.getCommand("target_page"); log.info(targetPage.getIdentifier()); log.info(targetPage.getClickable()); log.info(targetPage.getParent()); return new ModelAndView(new RedirectView("/cms/add/page/success", true)); }
Code:<form method="post" enctype="multipart/form-data"> <table> <tr> <th> Identifier: </th> <td> [@spring.bind "form_command_map.commandMap['target_page'].identifier"/] <input type="text" name="${spring.status.expression}" value="${spring.status.value}"/> ${spring.status}[@spring.showErrors ", " "fieldError" /] </td> </tr> <tr> <td> <p class="submit"><input type="submit" value="Add Page"/></p> </td> </tr> </table> </form>
The bind status ${spring.status} is:
The log output is:Code:BindStatus: expression=[commandMap['target_page'].identifier]; value=[];
The problem is, when i submit the form, the bind 'value' is never bound to the string property 'identity' of the target_page command object (which is stored in the hashmap). How can i make the form field 'commandMap['target_page'].identifier' set the identity property of the Page instance target_page.Code:2010-04-19 10:05:31,706 INFO [com.site.web.cms.form.controller.AddPageForm] - <> 2010-04-19 10:05:31,706 INFO [com.site.web.cms.form.controller.AddPageForm] - <true> 2010-04-19 10:05:31,706 INFO [com.site.web.cms.form.controller.AddPageForm] - <>
Any help is greatly appreciated.
Note: I'm using freemarker as my template language.


Reply With Quote