• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to handle a list in JSF 2

 
Ranch Hand
Posts: 563
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have what i believe is a simple question for those who are familiar with JSF.
I am not too familiar so before digging any further in the documentation i thought i'd ask here for advice.

My problem is quite simple: I want to display in a table the result of a JPQL query.
That query looks like this :
select a.name, b.title, b.age from table1 a, table2 b where a.id = b.id

So it returns a "list of lists" that looks like this:
((name1, title1, age1), (name2, title2, age2), ..., (nameN, titleN, ageN),

If i store the result of that query in an ArrayList (myList) in my Managed Bean, I can then do this in my XHTML page:



That of course does not work.
First because it displays the listing in one column only whereas there are 3 elements in each list. Secondly because item points to the list object, not an element of the list.

How do i do that in JSF 2 ? Maybe with EL ?

Thanks for helping.
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use h:dataTable like this

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if there are dynamic values and I am not aware of the number of record, then how can I do this.

Regards
Kapil Kumar
 
Saloon Keeper
Posts: 22989
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSF tag "language" is primarily about presentation. The number one problem here is that you have a variable presentation, so it's reasonable for JSF to expect that you'll be tweaking style info and related items to allow for that. There are a lot of options there, so they didn't try to cover them all.

The typical way to handle a situation like this is to dynamically build the columns. You do this by using a control binding reference (not a data reference) and coding a method in the backing bean to construct and lay out the columns.

Any given datatable must have a fixed number of columns, so if you want to display multiple sets of data with varying numbers of columns, each dataset would require its own datatable. If the number of sets of data is also variable, then you have to build that via control binding as well, making the datatables children of the parent container to which they are bound as well as dynamically binding columns to each datatable.

Although you think this is simple, it strikes me as classic "All You Have To Do Is" syndrome. While it's certainly not rocket science, there's more work involved than it would seem based on the basic requirements.
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
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