Two Laptop Bag*
The moose likes JSF and the fly likes Howto create a java.faces.model.ListDataModel in your backing bean 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 "Howto create a java.faces.model.ListDataModel in your backing bean" Watch "Howto create a java.faces.model.ListDataModel in your backing bean" New topic
Author

Howto create a java.faces.model.ListDataModel in your backing bean

Jenifer Rajakumar
Ranch Hand

Joined: Oct 31, 2013
Posts: 34
Hi

Iam very new to development. Iam just having one datatable, if i gave some input value and click on ok button, the data wants to show in datatable by some if condition.

For that i got the idea
1. to create a java.faces.model.ListDataModel in your backing bean and
2. call its getRowData() method from the action method in your backing bean
3. to get the item for which the action was taken

Iam very new so, how to create listDataModel in backin bean i don't know. Please give some code.

My Xhtml File



My DTO Class


My bean class


Please help me.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

The JSF DataModel classes are actually quite easy to use and they make JSF coding a lot simpler than the way so many people attempt to work with tables using View-side parameters and other cruft.

All that is required is this:

1. Change your "getList" method to return a DataModel object.
2. Create the Datamodel:


This version wraps the list as part of the model construction, but you can also build the model and wrap it around the list in a more primitive way:


You have the option of caching the list itself as an internal bean property or retrieving it from the model via getWrappedData, whichever suits you. Once wrapped, you don't have to re-wrap the list if it changes, only if you replace it with an entirely new List.

Note that when using model objects (DataModel or SelectItem), the bean that contains those objects cannot be Request-scoped, since the original model would be destroyed after its first use and a new instance would lack the context that had been created.


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

Joined: Oct 31, 2013
Posts: 34
Hi Tim


My doute is i want to create separate data Model class? or in bean class itself i can create.

Then how to call its getRowData() method from the action method in your backing bean. My action method was getList(). If My question is stupid sorry for that iam learning now only so please.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15959
    
  19

You can subclass DataModel and I often do, especially for tables where I keep totals. However, a DataModel is not intended to be a stand-alone backing bean, it's intended to provide the extra context that a POJO array or Collection needs in order to properly render and respond to rows in a dataTable. In actual fact, if you use a collection directly as the value of a dataTable, an anonymous DataModel is automatically created. But since it's anonymous, it's essentially impossible to use getRowData on it.

Your action method isn't getList(), it's action(). You use it like so:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Howto create a java.faces.model.ListDataModel in your backing bean
 
Similar Threads
JSF problem with form (update user)
Uncaught exception created in one of the service methods of the servlet Faces Servlet in application
Error when I select a given data p:datatable
Navigating page links with parameters