File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jenifer Rajakumar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jenifer Rajakumar
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic