| Author |
Showing database rows as columns
|
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
Hi guys, I know I can show all database rows on my JSF page through dataTable tag. However, such tag shows all informations in a ROW oriented way. How can I change this behavior and show every row in database on JSF page as columns. Example : B. Rgds. Edisandro. [ June 05, 2007: Message edited by: Edisandro Bessa ]
|
"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14561
|
|
For something simple like that, create a Vector<String[]> or List<String[]>. Copy the items over into a multi-column data list: For more complex collections, where you'd want multiple database columns to format in a single table column, things are a little more complex - perhaps best done by a custom JSF display tag.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
Thanks Tim for your prompt reply.
final int NUM_COLUMNS = 3; int colnum = NUM_COLUMNS+1; while ( rowset.next() ) { String[] cols; if ( colnum >= NUM_COLUMNS ) { cols = new String[NUM_COLUMNS]; list.append( cols ); colnum = 0; } else { cols = list.get(list.size()-1); } cols[colnum++] = rowset.getString("email"); } ListModel model = new ListModel(list);
That's the point I've fallen after thinking for a few minutes. I realized that I have to format my column oriented list inside the bean method such as getUsers() and then simply show it on my JSF page. However, I got another issue : In your code you defined the number of columns as a constant. Supposing the number of columns comes from an init parameter and that my getUsers method also has already formatted the user's list accordingly as you posted above. How can I dynamically create the <h:column> tags inside <h:dataTable> tag so that when the total columns defined as init parameter is reached the dynamic column creation stops ? I mean : If the number of columns defined in init parameter is three, the resulting JSF page could be something like <h:dataTable> <h:column>...</h:column> <h:column>...</h:column> <h:column>...</h:column> </h:dataTable> If the number of columns is four, the resulting JSF page could be something like <h:dataTable> <h:column>...</h:column> <h:column>...</h:column> <h:column>...</h:column> </h:dataTable> and so on ... How to dynamically create these columns ? Thanks a lot.
|
 |
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
Hi guys, Any ideas on how to dynamically create columns when using h:dataTable tag ?
|
 |
Edisandro Bessa
Ranch Hand
Joined: Jan 19, 2006
Posts: 584
|
|
Hi guys, For those interested I've just found a great Tomahawk component which I can use to dynamically create column in a dataTable. http://myfaces.apache.org/tomahawk/columns.html
|
 |
 |
|
|
subject: Showing database rows as columns
|
|
|