Results 1 to 3 of 3

Thread: Urgently need help about SessionAttributes ?? Can't get it work

Hybrid View

  1. #1
    Join Date
    Jun 2011
    Posts
    3

    Default Urgently need help about SessionAttributes ?? Can't get it work

    I have a controller which extend the class ControllerBase.

    Declare a SessionAttributes by annontation
    Code:
    @Controller
    @SessionAttributes(value = { "account", "action", "group", "groups", "groupUserMap", "notGroupUserMap" })
    @SuppressWarnings("unchecked")
    public class GroupController extends ControllerBase {
    A method declaration
    Code:
    @RequestMapping(value = "/group/list", method = RequestMethod.GET)
    	public String list(@RequestParam(required = false) String[] messages, @ModelAttribute Account account, Model model,
    			Locale locale) {
    At the end of the above method, the following attribute are put to model.
    Code:
    model.addAttribute("groups", groups);
    model.addAttribute("defaultGroup", defaultgroup);
    Another method in the same controller.
    Code:
    public String prepareAdd(@RequestParam(required = false) String groupName, @ModelAttribute Account account,
    			Model model, Locale locale) throws IOException {
    At the end of this method, it return to another view and need to access the previous defined model attribute "group" and "defaultgroup". But I found that the attribute are not there anymore. I put some debut code inside the method prepareAdd, iterate the model map and print out the entry set, and found that the group and defaultgroup entry are already cleared.

    I really don't understand why the SessionAttributes is not working. Anything I do wrong? Any hint how to use the SessionAttributes correctly?

    The software is written by others, and I'm very new to Spring, your advice would be very helpful .

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    Code:
    I really don't understand why the SessionAttributes is not working. 
    Anything I do wrong? Any hint how to use the SessionAttributes correctly?
    OK, just an observation, below

    Code:
    @SessionAttributes(value = { "account", "action", "group", "groups", "groupUserMap", "notGroupUserMap" })
    no appear or is not declared defaultGroup, where below you are referring

    Code:
    model.addAttribute("groups", groups);
    model.addAttribute("defaultGroup", defaultgroup);
    At the end of this method, it return to another view and need to access the previous defined model attribute "group" and "defaultgroup". But I found that the attribute are not there anymore. I put some debut code inside the method prepareAdd, iterate the model map and print out the entry set, and found that the group and defaultgroup entry are already cleared.
    If you could post the complete method implementation would be better, I hope in other method of your controller you are not clearing the Session, like status.setComplete();
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Jun 2011
    Posts
    3

    Default

    Thanks Jordon,

    Just find out that the previous insert a session.invalidate() statement in a method. I track down the session ID and fond that it's update during the navigation. Dig into the code and found that invalid statement. Problem already solved.

    Thanks anyway.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •