File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Need Help With Dynamic JSF Datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Need Help With Dynamic JSF Datatable" Watch "Need Help With Dynamic JSF Datatable" New topic
Author

Need Help With Dynamic JSF Datatable

mike housing
Greenhorn

Joined: Jul 21, 2010
Posts: 6
Hello, I'm hoping you guys can help, because I'm stuck. I'm trying to create a dynamic JSF datatable that has dynamic rows and columns and I'm using BalusC code as an example http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable I've entered his code and it works, but I'm confused on how it works because for his FOR statement he has it as I don't understand how it can iterate through the list when he has it .get(0). But on to my real problem, his code works for me for just creating a datatable and displaying the information, but what I need to do is loop through all the fields and see if they are null and if they are change the background color of the cell. With the way he has his code, I can't figure out how to iterate through the fields so I can see what each one's value is. I hope this makes sense and if you need me to re-word anything just let me know. Any help would be great thanks.
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
The get(0) part is easy to explain. He is using a matrix structure. He has a list of lists. The get(0) just returns the first list or the first "row" and he is iterating through it. So he is not going through the entire table but only the first row.

If you want to go through the entire table (every cell of the table) you can do it for example with two for loops. I leave it to you to learn how
mike housing
Greenhorn

Joined: Jul 21, 2010
Posts: 6
Well I was orignally going to do something like this:


but my problem is the actual creation of the column since i'm creating it within the second FOR loop, I can't add my output or input text boxes to the column.
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
The "usual" way of creating a html table this way would be to create the cells inside the inner for loop. But you do not do that here. If you want to see what your code does go each iteration (on both loops) over with a piece of paper and pen and see what is created as a result.

In any case if I understand correctly how BalusC:s code works you can not do what you intend to do here. The table is created automatically (by JSF) and BalusC:s code only tells JSF how many columns the table has and the names of the headers. But you try to create the entire table.
mike housing
Greenhorn

Joined: Jul 21, 2010
Posts: 6
Well this is what I’m trying to do ultimately, I know it’s not the best picture, but hopefully this will help. My table with have dynamic columns and rows and in each cell they will have inputText boxes with values. The user can change the values and update them if they want. What I need to be able to do is iterate through the table and check out all the values so that if one is null I can change the background color of the cell and display an error message. The only example I have found that comes close to what I'm trying to do is BalusC code, but it sounds like his code won’t work for me. Does anyone have any suggestions or links that would help me out? Thanks.


[Thumbnail for Dynamic Table.JPG]

 
jQuery in Action, 2nd edition
 
subject: Need Help With Dynamic JSF Datatable
 
Similar Threads
Rendering a List in a JSF page
Dynamically adding textboxes
InputText in DataTable does not store value
How to design a web based leave management application using jsf and spring (not springMVC)
generic method for similar classes