I’d like to display 2d array of floats in a table on a xhtml page using JSF2 and I have no idea how to do that. I tried to find the answer in google but I couldn’t. All examples were displaying classes objects and I was not able to make it working with the table.
The sitation is:
I have the array of some size – the size of the array depends on entered data:
float [][] variables = new float[size1][size2]
After user enters data and pressess button a method is called in the managed bean. The calculation begins and the table is filled with data.
Please tell me how can I display the array.
To achieve that you can use
c:forEachtag to dinamically buid ah:panelGrid. Just savesize2, which is the column number as a property and store all the input numbers in a normaljava.util.List. Then you set that size to theh:panelGridcolumnsattribute and the component will split the rows for you. You can also style the content inside thec:forEachtag, bordering it in order to give it a table behaviour.EDITED
If you want to maintain the original structure but in a List, you can create a
List<List<Float>>. That means a List which is composed by List which contains Float Objects. The same as a 2d array.In the code above I’m constructing the equivalent to a 2d array with 2 rows and values
1.0,2.0and3.0on each row. You can use this code to iterate it over the view:Where
#{backingBean._ColumnNumber}will be the length of the first array of the List (supposing all of them have the same length).Good Luck.