• Post Reply Bookmark Topic Watch Topic
  • New Topic

Facing problems with viewscoped managed beans  RSS feed

 
Raghu Sundar
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a primefaces editable datatable with column filtering feature.The datatable has live scrolling feature.The problem that i am facing here is that both filtering and scrolling are happening correctly with Request scoped managed bean but when the scope of the same bean is changed to view scope(javax.faces.bean.ViewScoped) then the filtering happens but on removing the keyed in key word from filter box the table content is not reset to original state and also i am not able to scroll down to next set of records on reaching the end of scrolling.Cell editing feature is working perfectly.

One thing that i observed is ,currently i am querying 5000 odd records to load into datatable.But if the number of records is limited below 5000 scrolling is happening correctly but problem with filtering remains same.I even tested by upgrading to Primefaces 5.1 from 3.5 but no luck .Can someone please help me how to resolve this issue,so that it works in view scoped.Thanks in advance

Code snippet of xhtml page



Managed bean



DAO class

 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised that it works at all. Request Scope is almost 100% useless in JSF.

In particular, it's useless for dataTables, because there's an intermediary object (the DataModel object) that's used to manage cursoring and line tracking for dataTables. I recommend that you create one explicitly, since if you don't, JSF will create an anonymous one anyway, but you won't have a way to take advantage of the DataModel's data-tracking functionality if it's anonymous.

The problem with Request Scope for a DataModel object is that it keeps critical information between page requests. But a Request-scope object gets destroyed between page requests. So your anonymous DataModel is being re-created as a blank object every time someone does a submit (including AJAX submits).

You should consider doing some sort of windowing on the back-end. 5000 records is a lot of precious server memory. Not too many users could visit that page at the same time before you ran out of RAM. Besides, after the first thousand records or so in the display, my eyeballs tend to start bleeding.
 
Raghu Sundar
Ranch Hand
Posts: 40
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for the reply.

To deal with large data live scrolling is implemented.Do i need to do something else to deal with large dataset?
As you suggested i tried explicitly implementing datamodel but its of no use.Scrolling,column filtering is not working.Cell editing which used to work before datamodel implementation is not working now,getting null pointer exception in the cell edit listener method,pointing the row id (which is the primary key in the POJO class)

Cell edit listener method snippet



The following are the changes i made with managed bean

managed bean


I referred lpModel as value attribute in the data table and removed the rowKey attribute.

Datamodel class
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you change your scope? As I said, Request scope causes critical information to be lost every time you submit.

Windowing on the backend can be done by hooking in AJAX scroll events from the dataTable and fetching the data via a range-limited database request. Many modern DBMS's cache context so that if you do a request and ask for, say 100 rows, then come back later and ask for 100 more, the overhead of building up the query from scratch is eliminated.

I don't know why you found it necessary to implement your own getRowData method, but it's designed to be capable of generating the nullpointerexception you're seeing.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!