Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
Ranch Hand
Posts: 34
  • 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.
 
Saloon Keeper
Posts: 22508
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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
  • 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
Posts: 22508
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • 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:

 
Because those who mind don't matter and those who matter don't mind - Seuss. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic