• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF [1.2] Managed bean [request scoped] constructor called twice during same request  RSS feed

 
Ajay Kamble
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

We are facing a strange scenario.

We have a jsf page and a request scoped bean. When we submit the page, if there are any validation errors then same page is displayed with errors.

On development machines only 1 instance of managed bean is created for above scenario.
[managed bean instance is created -> action method is called -> validation fails -> same page is rendered]

But on our test environment 2 instances are created for the same scenario,
[managed bean instance is created -> action method is called -> validation fails -> a new instance is created -> same page is rendered]

This issue is causing inconsistency in our application.

How do we control this behavior? Is there any configuration in faces-config.xml or web.xml?

*NOTE: We are using websphere portal 7.0 on test machines and 6.1 on local machines.
 
sathish Tl
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check pages are correctly ordered
 
Ajay Kamble
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by order?

Please note that in the given scenario there is only 1 page involved.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request scope is almost completely useless in JSF.

JSF uses a postback mechanism that results in multiple requests. Each request creates and destroys its own set of request-scope objects (if any were defined). A subsequent postback gets a whole new set of objects constructed.

Originally that meant that a lot of stuff that's traditionally Request scope had to be promoted to Session scope. JSF2 added View scope to get around that. Unfortunately, WAS 6.1 is quite ancient and doesn't support View Scope. Since it's a test environment, I recommend upgrading. Otherwise you'll have to use Session scope.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!