Questions tagged [view-scope]

The View Scope means that you can keep the object alive as long as you are staying on the view (page).

The @ViewScoped has been introduced by JSF 2.0 specification. In a nutshell the data which is @ViewScoped will keep living as long as you don't navigate to another page to itself. The view scope is very convenient, since it allows the pattern of initializing data when you first access a page (via a non-faces request, which is typically a GET request) and then keep that data when you work on the page, doing post-backs, AJAX requests, etc.

255 questions
32
votes
5 answers

Why does @PostConstruct callback fire every time even though bean is @ViewScoped? JSF

I am using datatable on page and using binding attribute to bind it to my backing bean. This is my code :-
TCM
  • 16,242
  • 43
  • 150
  • 245
31
votes
1 answer

@ViewScoped calls @PostConstruct on every postback request

This doesn't seem right. I was doing some cleanup of my code and I just noticed this. Every ajax request is firing the constructor and @PostConstruct of my @ViewScoped bean. Even a simple database pagination is firing it. I understood that…
Drew H
  • 4,629
  • 9
  • 55
  • 88
26
votes
5 answers

How to replace @ManagedBean / @ViewScope by CDI in JSF 2.0/2.1

I'm currently evaluating Java EE 6 / JSF 2.1 with RichFaces. A bean which is declared as @ManagedBean @ViewScoped Gets an ID set (to prepare e.g. a delete operation). Via JSF a confirmation popup is displayed. If the user confirms, the delete…
stacker
  • 64,199
  • 27
  • 132
  • 206
19
votes
2 answers

Are JSF 2.x @ViewScoped managed beans thread safe?

I've been googling for a couple hours on this issue to no eval. WELD docs and the CDI spec are pretty clear regarding thread safety of the scopes provided. For example: Application Scope - not safe Session Scope - not safe Request Scope - safe,…
Mark
  • 2,892
  • 16
  • 15
17
votes
1 answer

How and when is a @ViewScoped bean destroyed in JSF?

The lifecycle of the @RequestScoped and @SessionScopedBean managed beans are managed by the Servlet container itself since they are basically stored as an attribute of HttpRequest and HttpSession respectively. How do JSF manage the lifecycle of the…
Geek
  • 23,609
  • 39
  • 133
  • 212
16
votes
1 answer

Pass an object between @ViewScoped beans without using GET params

I have a browse.xhtml where I browse a list of cars and I want to view the details of the car in details.xhtml when a "View more" button is pressed. Their backing beans are @ViewScoped and are called BrowseBean and DetailsBean, respectively. Now, I…
Chris
  • 3,219
  • 8
  • 39
  • 61
11
votes
2 answers

How detect and remove (during a session) unused @ViewScoped beans that can't be garbage collected

EDIT: The problem raised by this question is very well explained and confirmed in this article by codebulb.ch, including some comparison between JSF @ViewScoped, CDI @ViewSCoped, and the Omnifaces @ViewScoped, and a clear statement that JSF…
11
votes
1 answer

@ViewScoped bean recreated on every postback request when using JSF 2.2

I'm having an issue similar to this post and the answer from @BalusC with 3 solutions but: I'm not using of the mentioned EL expressions I don't want to go with the second solution (it's complex enough for me like this) and partial state saving is…
Rima
  • 435
  • 2
  • 6
  • 16
10
votes
1 answer

@PostConstruct method is called even if the ManagedBean has already been instantiated (e.g. on AJAX-calls)

I have a @ViewScope ManagedBean and a @PostConstruct initialisation method. This method is called when a new instance is created, but also on every ajax call. Why is this so? On an AJAX-call the init-Method is called and executed, but no changes are…
elisman
  • 143
  • 1
  • 8
9
votes
3 answers

Will PrimeFaces Dialog Framework break view scope as compared to p:dialog?

I'm using PrimeFaces 5. I would like to open a dialog when a button is pressed. public void openUpload() { this.item = new Item(); …
Yichaoz
  • 7,886
  • 8
  • 45
  • 83
9
votes
1 answer

Linked ViewScoped beans lead to memory leaks

In our JavaEE6 project (EJB3, JSF2) on JBoss 7.1.1, it seems we have a memory leak with @ViewScoped beans. Last tree days I've spent time on this issue investigation. So i've created simple project with two pages to guarantee that after first page…
bohdanius
  • 93
  • 1
  • 4
9
votes
5 answers

JSF View scope in Spring

Is there any scope like JSF @ViewScoped in Spring 3.0? I have an application using JSF+Spring where backing beans are managed by Spring. I didn't find any scope like JSF wiew scope in Spring. I saw the blog Porting JSF 2.0’s ViewScope to Spring 3.0,…
khan
  • 2,606
  • 7
  • 35
  • 61
8
votes
2 answers

ViewExpiredException: No saved view state could be found: on submitting a form in JSF

I get the below exception while trying to submit a form. javax.faces.application.ViewExpiredException: /page1.xhtml No saved view state could be found for the view identifier: /page1.xhtml at…
8
votes
1 answer

How to access @ViewScoped managed beans from Servlets?

I would like to access a view scope managed bean inside a Servlet. I searched for similar question and got these ones: how to get beans from view scope which uses FacesContext.getCurrentInstance(), inapplicable inside a Servlet because it should…
Filippo
  • 951
  • 1
  • 8
  • 25
8
votes
2 answers

Are ViewScoped beans serialized to the page when client state saving is turned on?

We have client state saving turned on and use ViewScoped backing beans. When client state saving is turned on and we are using a ViewScoped bean, is the ViewScoped bean serialzied to the page or is it say, stored in session with a token/key that is…
BestPractices
  • 12,101
  • 27
  • 90
  • 134
1
2 3
16 17