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

JSF 2 Request scope and concurrency issue

Aakash Saxena
Greenhorn

Joined: Nov 11, 2012
Posts: 13

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

Joined: Jun 25, 2001
Posts: 16065
    
  21

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).


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

Joined: Nov 11, 2012
Posts: 13
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

Joined: Jun 25, 2001
Posts: 16065
    
  21

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF 2 Request scope and concurrency issue