• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@NoneScoped vs @RequestScoped?

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
What is the difference between NoneScoped and RequestScoped?
According to Stackoverflow's comments, a none scoped bean lives as long as the EL expression is evaluated. But when the none scoped bean's EL expression is evaluated in one request/response, it has already gone through the lifecycle such as restore view, apply request, process validation, update model, invoke application , render response.
And a request scoped bean has to go through all the cycle in one request/response.
 
Ranch Hand
Posts: 91
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi. My two cents for this one.

It might be that difference is that the bean (for the EL) has not "gone through the lifecycle", but that
it lives and dies up to the point that the EL result is resolved, all inside the request response lifecycle...

Could not find anything in the EL Spec about this...
 
Mano Ag
Ranch Hand
Posts: 91
Netbeans IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

Found some information in the JEE Tutorial (6) under Chap 14 Configuring JavaServer Faces Applications /...Using Managed Bean Scopes

"You may want to use @NoneScoped when a managed bean references another managed bean. The second bean should not be in a scope (@NoneScoped) if it is supposed to be created only when it is
referenced. If you define a bean as @NoneScoped, the bean is instantiated anew each time it is referenced, so it does not get saved in any scope."

Please note that the corresponding section in the JEE Tutorial (7) 16.1.1 is reworded and makes no mention of the @NoneScoped annotation.
 
Rancher
Posts: 517
15
Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:Hi, What is the difference between NoneScoped and RequestScoped?
According to Stackoverflow's comments, a none scoped bean lives as long as the EL expression is evaluated. But when the none scoped bean's EL expression is evaluated in one request/response, it has already gone through the lifecycle such as restore view, apply request, process validation, update model, invoke application , render response.
And a request scoped bean has to go through all the cycle in one request/response.



JSF spec 2.0's section 5.3.1 Managed Bean Configuration Example: This has an example of how a none scoped bean and a request scoped bean are configured and how they might be used together. To understand in detail you may have to write some code and verify the results. Here is the example:

A Customer bean with a request scope
An Address bean with none scope

The customer bean has attributes customer id, name, shipping address, billing address, etc. The shipping and billing address are of type Address. The customer bean creates an instance of address bean as shipping address and another instance as billing address; there will be two instances of address bean. The address bean instances do not have a scope, they are created as needed.
 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


index.xhtml


BeforeClick.JPG
[Thumbnail for BeforeClick.JPG]
Before click, fill out the name and the none scoped address
AfterClick.JPG
[Thumbnail for AfterClick.JPG]
After click, the user name is echo back, but not the address
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic