aspose file tools*
The moose likes JSF and the fly likes Need to understand the Request Scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Need to understand the Request Scope" Watch "Need to understand the Request Scope" New topic
Author

Need to understand the Request Scope

Jaaouane Aymen
Greenhorn

Joined: Sep 22, 2009
Posts: 29
Hello,
what is the real meaning of the request Scope in JSF?
Is the bean which is registered in the request scope remains alive until the render phase(last thing in the JSF Life cycle) or it is destroyed after the invoke application phase?
to understand me better, we assume that we have 2 pages: page1.jsp and page2.jsp. we assume also that after a post submitted in page1, page 2 will be dispalyed as a response. we assume that page1.jsp uses a backingbean called myBean and the page2.jsp uses
the same backingbean. my question is to process the jsf request which is the post to page2.jsp which comes rom page1.jsp, how the jsf engine will handle the request?
to display page2.jsp, is a new bean will be instancied to display page2.jsp or the same bean used in the lifecycle of page1.jsp will be used?
i hope my question is clear.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Request scope in JSF is exactly the same as request scope in general J2EE. It means that the object is defined as an attribute attached to the HttpRequest object and shares its lifetime. The HttpRequest object is created when the application container accepts an HTTP request from the client. It is effectively destroyed (goes out of scope) when the container has finished transmitting the response to that request. When a new HTTP request comes in, a new request-scope object is created. So anything that you want to exist between HTTP requests has to be placed in a longer-lived scope (such as session scope), or the data has to to be sent back as part of the response in such a way that it will be sent back as part of the next request.

For example, as a hidden field on a form that was rendered as part of the preceding response and with thus be sent back to the server as part of that form's submit process.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jaaouane Aymen
Greenhorn

Joined: Sep 22, 2009
Posts: 29
is that means that jsf will use the same instance of the backing bean for the whole life cycle of the jsf request?
is that means that the same instance of myBean will be used to validate and update the values of page1.jsp and then will be used to render page2.jsp?
Jaaouane Aymen
Greenhorn

Joined: Sep 22, 2009
Posts: 29
thank you tim for your help, but i am not speaking about session attributes or using hidden fields
to maintain state. my issue is the lifecycle of the backing bean of jsf when its scope is request.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Jaaouane Aymen wrote:thank you tim for your help, but i am not speaking about session attributes or using hidden fields
to maintain state. my issue is the lifecycle of the backing bean of jsf when its scope is request.


Request scope in JSF is exactly the same as request scope in general J2EE.

JSF uses J2EE's Request scope. It didn't invent something of its own and call it "request scope".

J2EE will construct request-scope Managed Beans as needed for the View to be presented and bind them to the request using the J2EE request.setAttribute method the exact same way you would do it manually. When the J2EE request goes out of scope, all its dependent objects go out of scope at the same time. Including all request attributes. JSF or otherwise.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to understand the Request Scope