Hello-
I am using a session scoped bean in my web application, but it turns out these objects are not distinct across sessions. One user's object ends up being "used" by another. I have a "UserLog" object that has some member variables, public setters/getters, and a resetUserLog that just sets the member variables to null and -1s.
Application Context
ControllerCode:<bean id="newUserLog" class="org.nyumc.patientlog.domain.object.UserLog" scope="session"> <aop:scoped-proxy proxy-target-class="true"/> </bean>
This has been simplified, but not in a way that should matter for understanding what I am doing.
So, a user log can consist of multiple pages. I store the user log in the session so that this information entered remains from page to page, then I save the entire log at the end. If a user clicks a special "save and add another with this data" button [ see 'createAnother' above], I save the form, then show the first page of the log again with everything saved (because it should be saved in the newUserLog session scoped bean). Instead, when the user is brought to the first page of the new log, this first page is a DIFFERENT user's log, and therefore this newUserLog bean seems to be used across sessions. Why??Code:@Controller public class UserLogController { @Autowired @Qualifier("newUserLog") private UserLog newUserLog; public String returnToLogPage(int pgnum, Model model){ newUserLog.setCurPage(pgnum); newUserLog = userLogManager.getNewUserLog(programId, formId, sessionManager.getUser(request).getId()); model.addAttribute("logPage", newUserLog.getPages().get(pgnum)); return "User/log"; } @RequestMapping(value={"/createNewLog.html"}) public String newLog(@RequestParam int programId, @RequestParam int formId, Model model, HttpServletRequest request){ newUserLog.resetUserLog(); return returnToLogPage(0, model); } @RequestMapping(value="/userLog.html", method=RequestMethod.POST) public String userLogSave(@ModelAttribute("logPage") UserLogPage logPage, Model model, HttpServletRequest request){ int goToPage = Integer.parseInt(request.getParameter("goToPage")); for(int k = 0; k < logPage.getUserElements().size(); k++){ newUserLog.getPages().get(0).getUserElements().get(k).updateElementWithResponses(logPage.getUserElements().get(k)); } if(newUserLog.getTotalNumPages() >= goToPage){ return returnToLogPage(goToPage, model); }else { userLogManager.saveNewUserLog(newUserLog, sessionManager.getUser(request), false); if(request.getParameter("createAnother") != null && request.getParameter("createAnother").equals("y")){ return returnToLogPage(1, model); } return "redirect:newLogHome.html?from=newlog"; } }
Clea


Reply With Quote
