Spring - SessionAttribute problem
- by Max
Hello,
I want to implement something like this:
@Controller
@SessionAttributes("promotion")
class PromotionController {
@RequestMapping("showPromo")
void showPromotionInfo(
@RequestParam("promId") String promotionId,
@ModelAttribute Promotion promotion, Errors errors
) {
promotion = Promotions.get(promotionId);
if (promotion == null || promotion.validates() == false) {
errors.reject("promotion.invalid");
}
return "prom";
}
}
The code is invalid, wont work and has some bad errors, but I don't know how to write it better.
When user comes to an URL "showPromo?promId=15", controller should validate if the promotion is valid (outdated/non-existent/etc.). If it is valid - it should show it's information and save the promotion to model and session. If it's not - it should show some error about promotion being invalid.
Problem is, I need to save the promotion in the session (for several requests) and don't want to use direct session management. Is it currently possible with Spring? Or am I doing something wrong?
Could you please provide the optimal solution to my problem using Spring 3?
Thanks in advance.