This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

JSF presentation of results from several records on one line  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have  tables of cars (id, brand, model, variant, price). In java i have List <Cars>. Each model has three price variants.

Example data:
1 OPEL CORSA 1 10.000
2 OPEL CORSA 2 15,000
3 OPEL CORSA 3 20,000
4 OPEL ASTRA 1 21.000
5 OPEL ASTRA 2 31.000
6 OPEL ASTRA 3 41.000

I would like to display it in JSF in this form:
Brand Model Variant 1 Variant 2 Variant 3
OPEL CORSA 10,000 15,000 20,000
OPEL ASTRA 21.000 31.000 41.000

How can I combine this data to make it as easy as possible to display in jsf?
 
Saloon Keeper
Posts: 20505
115
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Carl!

Basically, you need a data model whose structure is something like this:



I've omitted the grunt code (constructors, getters/setters) for clarity. You'd then build a collection (for example an arrayList) of ModelStats and a DataModel to wrap it. That is,


Since you're doing a tabular display, the View Template would follow the following form:


You have 2 choices for MAGIC_STUFF.

The first, and easiest overall is to add an aggregating property-get method to format the numbers as a single String that can be rendered via an h:outputText. That is:


This code may require tweaking, since you're dealing with a list of integers here.

The second method can be done without hacking the model element class:



As coded, this would print a trailing comma, but I think that you can use the ui:repeat varStatus attribute to control that.

The ui:repeat and h:dataTable are a lot alike, but h:dataTable renders as a 2-dimensional object with the elements arrayed in rows, whereas ui:repeat simply repeats its contents verbatim, leaving it up to you to do the actual layout. Also, h:dataTable employs a DataModel that can be queried in action code to determine which row the link, button, or AJAX control that was fired is in.
 
Carl Sopel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for Your post. I dont want to create new class. Is another option for example use map or some collection?
 
Tim Holloway
Saloon Keeper
Posts: 20505
115
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so. The dataTable wants flat data. Your data isn't flat.

There's nothing wrong with creating a UI model helper class - unless you're forbiddent to do so by an idiot employer. Most IDEs make it very easy to generate simple javabean classes via a code wizard.

You don't even need to create a separate class file, since this is something used only within the backing bean.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!