• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Need to understand the Request Scope

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 24199
166
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jaaouane Aymen
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24199
166
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what the real world use cases of bean scopes ?
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic