• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to count the number of views created in a Session while using a managed bean with View Scope.

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

I am trying to restrict the number of views in JSF 2.0.2 using

In my case my managed bean is View Scoped and it supports a UI page which has multiple forms and each form is submitted as AJAX POST request.
As per the statndard, setting restriction to 5 should create 5 views and after that based on LRU algorithm the oldest views should get deleted if 6th views is created.
Therefore any action on the oldest view will throw the ViewExpiredException and i simply redirect the user to view expired page.

1) When i set the restriction to 5 views, i open 4 tabs with 3 forms each.
2) I submit the 3 forms on first tab everything works fine.
3) As soon as I go to 2nd tab and submit the first form thr, i get view expired exception
4) It seems I am exceeding the number of views I mentioned in web.xml


I want to know :
1) Does every AJAX POST submit itself creates a view ?
2) How I can count the number of views created in a session ?
3)Can i force expiry of a view in JSF 2.0.2 while the session is still alive ?
4) Normally JSF 2.0.2 session cachces the views. Lets assume session is alive the entire day but a view was created in morning at 9:00 AM and is not used again the enire day. Assuming that session doesn't reaches the max number of views it can save in entire day, will the view created in morning expire on its own after certain interval of time ? If not , can we still force its expiry while keeping the session alive ?
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, a bigger problem is that you're using multiple tabs.

A) As a user, I hate apps like that. It's one of the top 5 ways to lose a sale from me (#1 is auto-playing multi-media with sound).

B) JSF does not come with a way to enforce data integrity when more than one View is displayed at one.

To expand on B, let's say that you have 2 windows/tabs. One is a parent View of a table. The other is the detail (child) view. Because of how HTTP works, if you change detail properties, the parent view will NOT automatically receive updates as it would in a "pure" MVC system (JSF is as pure MVC as you can get for a request/response system, but lacks the ability to asynchronously update Views, because HTTP doesn't permit that. You have to supply user-written AJAX code or something similar).

Worse yet, the stock J2EE object system doesn't support multiple model instances. If you open up a child edit window and then switch over to the parent table and select a second child window, you're going to experience major data corruption. That's because the two views are both using the exact same model instance. The HttpSession object that contains session-scope objects is a simple Map where names must be unique and each backing bean is filed under its own name. Even View Scope can't help, since View Scope is essentially just a self-deleting Session object. And don't even think about using Request Scope or you'll spend the rest of your career fighting vanishing properties.

A View is a presentation of a Model based on a given View Template. It is rendered in a display (window or tab). As with any true MVC system, you can have multiple Views into a Model, although, as I said, JSF cannot automatically refresh displays to keep all of the renditions in sync. So the multiple-View aspect applies only within a single display. For example, a web page containing both a table and a graph of the same Model data. The View itself doesn't contain processing data; that's what the Model is for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!