java - Spring - SessionAttribute problem -


I want to apply something like this:

  @Controller @ session attraction ( "Promotion") {@RequestMapping ("ShowPro") Zero Shows Promotion Info (@RequestParam ("promId") String Promotional Id, @model Unbreakable Promotion, Errors Errors) {promotion = Promotion.get (promotionId); If (promotion == empty promotion. Validates () == incorrect) {errors.reject ("promotion.invalid"); } Return "Prom"; }}  

The code is invalid, does not work and there are some bad errors, but I do not know how to write it better.

When the user has a URL "showPromo? PromId = 15", if the promotion is valid (old / non-existent / etc) controller must be valid. If it is valid - it should show its information and save the model and session promotion. If it is not - should show some error about the promotion.

There is a problem, I need to save the promotion in session (for many requests) and do not want to use direct session management Is it currently possible with spring? Or am I doing something wrong?

Can you provide the optimum solution to my problem using Spring 3?

Thank you in advance. Added:

OK, I think I will write problematic points:

  1. If there is no object in the session, then it @Model can not be bound with properties such as "no objects found in the session" and there is no "optional" parameter anywhere.
  2. I can not get @ModelAttribute in the parameters, because I overwrite that promotion object should be a proper way model. AddAttribute ("promotion", promotion) but there should also be a way of providing errors, and I have no way of using the model. AddAttribute. In addition to the answer to Schifen: Binding result s manually added model attribute You can use the BindingResult.MODEL_KEY_PREFIX . .
      Promotion Promotion = .... Modelmap.adArbit ("Promotion", Promotion); If (! Promotion.validate ()) {Compulsive Results Errors = New Bean Posterbearing Richest (Promotion, "Promotion"); Errors.reject ("promotion.invalid"); Model.put (BindingResult.MODEL_KEY_PREFIX + "Promotion", Errors); }  

    Note, however, that you can not associate the binding result to the null object, so you can see the Errors. Rejected promotion (if you do not add any kind of empty promotion in that case).


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -