tags:

views:

475

answers:

1

I have some misunderstanding with JSF backing bean scope. I am newbie in JSF and now write simple project and all my beans mostly have session scope. But if my site will have many users that's mean my session will be very very big and this kill my server. Some people said my that solution is use request scope beans. But, for example, when my page must be validated and if validation is failure show error messages and save all user input, what can i do in this situation. I am trying use component that use AJAX-request and hoped that my request bean will be not reconstructed, but this doesn't work( I am use <rich:datascroller> ).

I think I have big hole in my JSF understanding, it will be grateful if somebody explain what I must do in this situation or link me on some good article about bean scopes.

+2  A: 

Scope defines the lifetime of the beans.

Request scope beans live during the servicing of one HTTP request, so thay are available both while you analyze the user's input and formulate the response page. So for simple validation and response I'd expect request-scoped beans to be what you need - the exception being perhaps if you send a redirect back to the browser and that submits a new request, then you may need ...

Session scoped beans live for the life of the user's session, ie. across several requests. Sessions might last for some time, but eventually the user logs out, or becomes quiscent and his session gets timed-out. So it doesn't matter how many users overall you have, just how many are active at once. It's pretty common to keep some session data around for each user (like at least who is, and perhaps his recently viewed stuff) so there's no fundamental reason to be worried by some data being kept. You just need to ensure you keep it tidy, don't keep the data for old pages very very long - perhaps just a "current data" bean or some such.

djna
But what with AJAX-request, I think that it will not cause new bean construction but it does. How can I perform this "simple validation and response"?
masterzim
Are we talking about the servicing of a single AJAX request? The page is already rendered before this happens, right? I would expect a single request scope bean to be used in that Ajax request/response, with no relationship to whatever beans were used in drawing the original page. Now maybe you are using some "helpful" framework which is doing more?
djna
When you get a page, you do the request, it renders and sends the request back. Then the request scoped bean is tossed. Then, you do a new AJAX request which builds all the new beans it may need and sends the response. So yes, AJAX requests will create new Request scoped beans. They are, afterall, AJAX *requests.*
Drew