Reputation: 2072
I have a ArrayList of ArrayList - I declare it in this way:
ArrayList<ArrayList<String>> queryResult=new ArrayList<ArrayList<String>>();
Then I add a new element to array like this:
for(int i=1;i<colNumber;i++)
{
queryResult.add(new ArrayList<String>(20));
}
after that I add a value to elements of array:
while(r.next())
{
for(int i=0;i<colNumber;i++)
{
queryResult.get(i).add(r.getString(i));
}
}
But when I try to use it in DataTable tag I see nothing :(
<h:dataTable value="#{polaczenieSQL.queryResult}" var="w">
<h:column>
<f:facet name="head">typ</f:facet>
#{w[0]}
</h:column>
What I am doing wrong? How should I use this array in JSF?
Ps this is my faces.config:
<managed-property>
<property-name>queryResult</property-name>
<property-class>java.util.ArrayList</property-class>
<list-entries></list-entries>
</managed-property>
I found first problem:
r.getString(i)
I added a
System.out.print("something")
after a loop but it doesn't want to print.
When I change a variable 'i' and type for example: 4 I see "something" on my console . Variable 'colNumber' is set to 5 (but my sql table have 7 columns and I use "select * from mytable" so I dont think that is a counter problem ).
Upvotes: 3
Views: 3138
Reputation: 7920
If you want to print all the values in the inner list you should do as following:
<h:dataTable value="#{polaczenieSQL.queryResult}" var="w">
<h:column>
<f:facet name="head">typ</f:facet>
#{w[0]} <!--will print the first element in the inner list-->
</h:column>
<h:column>
<f:facet name="head">typ</f:facet>
#{w[2]} <!--will print the second element in the inner list-->
</h:column>
...
<h:column>
<f:facet name="head">typ</f:facet>
#{w[n]} <!--will print the nth element in the inner list-->
</h:column>
</h:dataTable>
so basically if you want to print all the values of a inner list you can use the following style:
<ui:repeat value="#{activeUser.listInList}" var="innerList">
<ui:repeat value="#{innerList}" var="innerListValue">
#{innerListValue}
</ui:repeat>
</ui:repeat>
And about exception swallowing, you should throw an exception whenever you catch one unless you know exactly what you are missing.
Upvotes: 2