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, does not work, and has some bad errors, but I don’t know how to write it better.
When the user arrives at the URL "showPromo? PromId = 15", the controller must check if the stock is valid (obsolete / does not exist / etc.). If it is valid, it should show information and keep moving along the model and session. If this is not so, it should be incorrectly indicated that the promotion is invalid.
The problem is that I need to keep the promotion in the session (for multiple requests) and do not want to use direct session management. Is this possible with Spring? Or am I doing something wrong?
Could you suggest an optimal solution to my problem using Spring 3?
.
:
, , :
- , @ModelAttribute, , "no object found in session". "" .
- @ModelAttribute , . model.addAttribute( "", ). , model.addAttribute.