Hi Guys,
I'm new to the Spring MVC side of things and I'm currently trying to learn how to develop a portlet (hosted within liferay). So far everything seems to work - but I have one snag which I'm stuck on, and would be grateful if someone could shed some light on it for me please?...
basically, I have a portlet page which displays a "search" form - when the user completes the form and searches - I return a list of "cases" the user can select from - However, if they then go back to the search screen and change their search criteria - the new results are returned BUT so are the previous search results (this list gets added to continually)...
My (untrained) eye is telling me that I need to reset the contents of the Model attribute to null or remove it before re-populating it with the new data - but I'm not sure what way I should do this (hence my call for help!)
My code is below (apologies if it's badly written but I am still only learning as I go - so any improvement comments would be great also)
Code:package com.test.portlets.controller; ...imports removed to shorten code... @Controller(value="searchCaseController") @RequestMapping(value = "VIEW") public class CaseSearchController { @Autowired @Qualifier("myCaseServiceImpl") private CaseService caseService; List<Case> caseSearchResults; private Logger logger = Logger.getLogger(CaseSearchController.class); public void setCaseService(CaseService caseService) { this.caseService = caseService; } @ModelAttribute("caseSearch") public CaseSearch getCommandObject() { logger.info("Creating Case command object"); return new CaseSearch(); } @RenderMapping(params = "myaction=searchCase") public String showAddCaseForm(RenderResponse response) { return "caseSearch"; } @ActionMapping(params = "myaction=searchCase") public void searchCase(@ModelAttribute CaseSearch aCaseSearch, BindingResult bindingResult, ActionResponse response, Model model) { logger.info("Inside searchCase action method"); if (!bindingResult.hasErrors()) { String caseStatus = aCaseSearch.getStatus(); logger.info("About to get cases with [" + "caseRef: "+ aCaseSearch.getcaseRef() + ", Status: " + caseStatus + ", Limit: 20]"); caseSearchResults = caseService.getCases(aCaseSearch.getcaseRef(),caseStatus , 20); model.addAttribute("caseSearchResults", caseSearchResults); response.setRenderParameter("myaction", "searchCase"); } else { response.setRenderParameter("myaction", "searchCase"); } } @ModelAttribute("caseStatus") public Map<String, String> populateCaseStatusList(){ Map<String, String> status = new LinkedHashMap<String, String>(); status.put("Open", "Open"); status.put("Closed", "Closed"); return status; } }
Any help would be great..
Thanks


Reply With Quote
