Hello,
I have a controller to edit an entity (called an "agent"). The agent is linked to a timezone so I'm supplying the timezone strings via a @ModelAttribute so the jsp can show them in an HTML select input control. Here's my controller for editing agents:
The problem I'm having is that when the submit is invoked and there's no validation errors, the redirect doesn't work properly. Why? Because the timezoneIds are getting tacked on the end of the url to be redirected to. I happen to have the UrlRewriteFilter in debug still and here's what it's trying to do (scroll right to see the URL):Code:@Controller @RequestMapping(AgentEditController.viewName + "/{agentId}") @SessionAttributes(AgentEditController.modelAttrName) public class AgentEditController { public final static String viewName = "/ag/agents/edit"; public final static String modelAttrName = "agent"; @Autowired private MainServices mainServices; private Log log = LogFactory.getLog(AgentEditController.class); @RequestMapping(method = RequestMethod.GET) public String setupForm(@PathVariable int agentId, HttpServletRequest request, ModelMap model) throws Exception { WebAgent agent = new WebAgent(mainServices.findAgentById(agentId)); model.addAttribute(modelAttrName, agent); return viewName; } @ModelAttribute("timezoneIds") public List<String> getTimezoneIds() { return StaticReferenceData.getTimezoneIDs(); } @RequestMapping(method = RequestMethod.POST) public String processSubmit(@ModelAttribute(modelAttrName) WebAgent agent, BindingResult result, SessionStatus status) { new WebAgentValidator().validate(agent, result); if (result.hasErrors()) { return viewName; } else { mainServices.updateAgent(agent.createModelAgent()); status.setComplete(); return "redirect:/ag/agents/list"; } } }
Is this happening by design? I can stop it happening by getting rid of this:Code:ServletContext.log():org.tuckey.web.filters.urlrewrite.UrlRewriter DEBUG: processing outbound url for /myapp/ag/agents/list?timezoneIds=ACT&timezoneIds=AET&timezoneIds=AGT&timezoneIds=ART&timezoneIds=AST&timezoneIds=Africa%2FAbidjan&timezoneIds=Africa%2FAccra&timezoneIds=Africa%2FAddis_Ababa&timezoneIds=Africa%2FAlgiers&timezoneIds=Africa%2FAsmara&timezoneIds=Africa%2FAsmera&timezoneIds=Africa%2FBamako&timezoneIds=Africa%2FBangui&timezoneIds=Africa%2FBanjul&timezoneIds=Africa%2FBissau&timezoneIds=Africa%2FBlantyre&timezoneIds=Africa%2FBrazzaville&timezoneIds=Africa%2FBujumbura&timezoneIds=Africa%2FCairo&timezoneIds=Africa%2FCasablanca&timezoneIds=Africa%2FCeuta&timezoneIds=Africa%2FConakry&timezoneIds=Africa%2FDakar&timezoneIds=Africa%2FDar_es_Salaam&timezoneIds=Africa%2FDjibouti&timezoneIds=Africa%2FDouala&timezoneIds=Africa%2FEl_Aaiun&timezoneIds=Africa%2FFreetown&timezoneIds=Africa%2FGaborone&timezoneIds=Africa%2FHarare&timezoneIds=Africa%2FJohannesburg&timezoneIds=Africa%2FKampala&timezoneIds=Africa%2FKhartoum&timezoneIds=Africa%2FKigali&timezoneIds=Africa%2FKinshasa&timezoneIds=Africa%2FLagos&timezoneIds=Africa%2FLibreville&timezoneIds=Africa%2FLome&timezoneIds=Africa%2FLuanda&timezoneIds=Africa%2FLubumbashi&timezoneIds=Africa%2FLusaka&timezoneIds=Africa%2FMalabo&timezoneIds=Africa%2FMaputo&timezoneIds=Africa%2FMaseru&timezoneIds=Africa%2FMbabane (lots and lots more timezones removed)
and putting another addAttribute call in setupForm():Code:@ModelAttribute("timezoneIds") public List<String> getTimezoneIds() { return StaticReferenceData.getTimezoneIDs(); }
but I have other submit methods (not shown for brevity) that add and remove bits of the agent and I'd need to add the calls in those handlers also.Code:@RequestMapping(method = RequestMethod.GET) public String setupForm(@PathVariable int agentId, HttpServletRequest request, ModelMap model) throws Exception { WebAgent agent = new WebAgent(mainServices.findAgentById(agentId)); model.addAttribute(modelAttrName, agent); model.addAttribute("timezoneIds",StaticReferenceData.getTimezoneIDs()); <--- line added return viewName; }
My question again is is this by design and what's the preferred/safe/succinct way of doing what I want to do?
Thanks,
PUK


Reply With Quote

