wood burning stoves 2.0*
The moose likes JSF and the fly likes Jsf Data table values are coming as null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Jsf Data table values are coming as null" Watch "Jsf Data table values are coming as null" New topic
Author

Jsf Data table values are coming as null

Stanley Walker
Ranch Hand

Joined: Sep 23, 2009
Posts: 87
I am totally new to JSF and as an exercise i was creating a sample application. In this application once login is complete a data table will be populated with dynamic values(for the time being it is junk values). I have been able to do the navigation and even the datatable shows upto the right number of rows however no values are shown in the data table. Please help , even after reading several solutions(most of which are pretty much similar to what i have done) i am clueless.

The flow is index.jsp ---on login ----> LoginSucces.jsp

code for index.jsp is



the faces-config.xml is



the code for LoginSuccess.jsp is



most importantly the code for managed bean for the index.jsp is IndexBean.java the code for whicih is




Account.java is a simple pojo






What am i doing wrong? Is there some problem with the scoping? during the rendering phase are the values getting reset to null ? if so , how come onve invoked thescreen shows right number of rows for the table.


I apologize before hand for the rudimentary approach I have taken above, i am still learning. I would be garteful for any help.












Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Actually, that was a bit more information than I could easily read on-screen.

But unless I missed the forest for the trees, you're attempting to supply the dataTable control with data straight from a list of data rows.

JSF doesn't work that way. The dataTable and select controls require their corresponding Model data to be encapsulated in a class that facilitates proper operation of the associated tag's Controller.

Specifically, a dataTable cannot be supplied from a List, it has to be modelled by a javax.faces.DataModel.

There are several classes for this, depending on how the underlying data is supplied. In your case, use the ListDataModel.

It's easy to instantiate such an object. Just supply your List as an argument to the ListDataModel constructor. Or add/replace it after the fact using the setWrappedData method.

The DataModel cannot be dynamically created by a "get" method because it contains the ongoing context used by the Controller to enumerate the rows of the table. In other words, it should be a fixed property of the backing bean class. Create it once and return that object on "get" requests for the table model. Also, the backing bean containing the table model has to be at least View scope (JSF2) or Session scope (JSF 1). Request scope doesn't work except for display-only purposes. If you intend putting input controls or commandlinks in the dataTable, that's not sufficient.


Customer surveys are for companies who didn't pay proper attention to begin with.
Stanley Walker
Ranch Hand

Joined: Sep 23, 2009
Posts: 87
Thank you Tim for your reply.I read it multiple times and tell me if I am right in my analysis

1. backing bean will have a field of type listDataModel, along with its getter setters.
2. in jsf i will have <h: data Table value="#{bakcingbean.listDataModelName}"
3. listDataModel has to be created using the list as an argument.

Is that right? I do have to do any further?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

Stanley Walker wrote:Thank you Tim for your reply.I read it multiple times and tell me if I am right in my analysis

1. backing bean will have a field of type listDataModel, along with its getter setters.
2. in jsf i will have <h: data Table value="#{bakcingbean.listDataModelName}"
3. listDataModel has to be created using the list as an argument.

Is that right? I do have to do any further?



Try it and see!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsf Data table values are coming as null
 
Similar Threads
Birth Date nightmare - passing variable between beans and java objects
SINGLE LINE EDITING OF A JSF DATATABLE
Providing anchor to columns in a datatable
problem JSF - datatable from DB
commandLink not working in datatable+jsf2.0