13 Replies Latest reply: Feb 24, 2012 3:22 PM by 892826 RSS

    Setting SessionScoped as an annotation

    892826
      Hi, i have a doubt regarding the annotation SessionScoped. Should we use more than one session or is it make sense to set two beans in SessionScoped at the same time?
        • 1. Re: Setting SessionScoped as an annotation
          EJP
          What do you mean 'use more than one session?' You can't do that.

          You can put as many beans as you like into session scope, but keep their total size small or your application won't scale.
          • 2. Re: Setting SessionScoped as an annotation
            892826
            I mean that can i have more than one bean which are declared as SessionScoped at the same time? Is it recommended? or i am just thinking wrongly???
            • 3. Re: Setting SessionScoped as an annotation
              gimbal2
              SessionScoped beans are kept in the (user) session and will survive for as long as the session survives. Don't make it any more difficult than it has to be. Yes, you can have as many beans in there as you want, just like you can store as many objects as you want in the session manually. If it is actually a good idea is a whole different discussion, it depends fully on the application architecture. Likely at least some of them should be ViewScoped.

              I tend to use SessionScoped beans to store things like search parameters - so on a page where you can perform a search, if you go back to that page at a later time the parameters you input the last time are still there and in effect. The search results, likely a list of objects selected from the database, I do not store in the SessionScoped bean; I store those in a RequestScoped bean (which means for a search page I will likely have two separate managed beans) so the results are retrieved fresh and up to date with each request made.
              • 4. Re: Setting SessionScoped as an annotation
                892826
                okkkk...... thank you so much...
                • 5. Re: Setting SessionScoped as an annotation
                  EJP
                  what do you mean 'use more than one session?'
                  I mean that can i have more than one bean
                  I see, you meant the opposite of what you said. Not very useful.

                  Please express yourself clearly. It just wastes everybody's time otherwise.
                  • 6. Re: Setting SessionScoped as an annotation
                    892826
                    Hey EJP, I was simply asking that is it make sense to have more than one managedBean in SessionScoped at a time?
                    • 7. Re: Setting SessionScoped as an annotation
                      EJP
                      No you weren't. In your original question you were asking about using more than one session. It's up there in black and white. That's why I asked you to clarify, which you did. If you had expressed yourself correctly in the first place it wouldn't have been necessary. The idea is to say what you mean, rather than waste everybody's time. I don't care about yours, but mine is valuable.
                      • 8. Re: Setting SessionScoped as an annotation
                        892826
                        Hello EJP, i am really sorry, if it was not correctly asked but seriously i didn't want to waste anyone's time, who are here. Still i have the same question. "is it make sense to have more than one managedBean in SessionScoped at a time?"
                        • 9. Re: Setting SessionScoped as an annotation
                          r035198x
                          Ravi wrote:
                          ...Still i have the same question. "is it make sense to have more than one managedBean in SessionScoped at a time?"
                          Read gimbal's reply again. There are times when it makes sense and to do so and times when it does not make sense. We don't know the problem you are trying to solve so we don't know if it makes sense for your scenario or not.
                          • 10. Re: Setting SessionScoped as an annotation
                            gimbal2
                            r035198x wrote:
                            Read gimbal's reply again. There are times when it makes sense and to do so and times when it does not make sense. We don't know the problem you are trying to solve so we don't know if it makes sense for your scenario or not.
                            Bingo. Wouldn't you know it: programming is hard, software development is even harder. Ah if only you could just throw any question in a forum and get a cookie cutter answer as a result... life as a developer would be so horribly boring.
                            • 11. Re: Setting SessionScoped as an annotation
                              892826
                              Hello gimbal and r035198x, I already got the answer posted by you (gimbal), but EJP has some doubt regarding the question. That is why i was requesting to EJP and trying to explain him that i don't mean what you (EJP) understand. That post was written for EJP.
                              Once gimbal posted his answer, i marked the thread as "answered". because i got the answer.Thank you gimbal.
                              • 12. Re: Setting SessionScoped as an annotation
                                EJP
                                Rubbish. I don't have any 'doubt regarding the question'. I agree with the answer given 100%. My issue is your incorrect problem statement and then your strange reluctance to admit it ("I was simpy asking ...") when you weren't, and which still continues: "still I have the same question". It wasn't the same question, you changed it halfway through the thread.
                                • 13. Re: Setting SessionScoped as an annotation
                                  892826
                                  EJP: My question was already answered currently. However i wrote this whole essay to explain myself. Now i am quitting. Hope you won't mind it anymore. m sorry.