Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF 2 Request scope and concurrency issue

 
Aakash Saxena
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Experts

I have a question here related to JSF's request scope.

I have a bean class with the scope type as "Request".

Mine is a single page application and I have defined all the properties/attributes I need to show on the page at classe level in the managed bean. For ex, this is how my class looks like :

public class OfferTableContent {

public String callingApplication;
public String numberOfOffers;
public Offer offer
public offerLabel
public HtmlDataTable offerTable;
}

As far as I know, properties if defined at class level can give concurrency issues.

However, in my case, since the scope type of managed bean is "request", I am assuming that each new request will create a new instance of bean, therefore the class level properties will have their own state for each request and so no concurrency issues will be faced.

Please correct me if I am wrong.

Regards
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are quite correct. Request-scope objects are immune to concurrency problems because they are attached to a single processing thread and only live while that thread is processing a request.

However, because of JSF's postback system, Request-scope objects are also almost useless.

A Session or View scope object isn't totally immune to concurrency issues, but the only interference can come from the same user and then only if they're doing something silly like triple-clicking submit buttons (which serves them right).

 
Aakash Saxena
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Tim.

I am using spring 2.5 in my project and my JSF managed bean (manged bean is request scoped) is present in my spring context file.
By default Spring creates a single instance for all the beans defined in context file.
Do you think, despite placing the JSF managed bean in spring context file, I would still get a new instance each time a new request comes ?

Just to let you know, scope = "prototype" in spring context file didn't work for me.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put a bean in the Spring configuration, it is not a JSF managed bean (any more). It is a Spring managed bean, and by default that means it's an application-global singleton object. Which technically isn't a J2EE object, but it works, so who cares?

JSF and Spring each manage their own sets of beans according to their own rules. The JSF/Spring EL bridge module that you configure in faces-config allows them to be used interchangeable in EL expressions. But to give a bean J2EE/JSF Request Scope you have to define it as a Request Scope bean in either faces-config.xml or via JSF2 annotation. You can't define it as such in Spring and expect the JSF functionality.

The same applies to the other J2EE scopes (View, Session, and Application).

Request scope, as I've mentioned before, is almost totally useless in JSF. Because of JSF's postback mechanism, a lot of things you'd use request scope for on other J2EE platforms will fail under JSF.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic