[英]jsf-arrayList of arrayList in JSF
I have a ArrayList of ArrayList - I declare it in this way: 我有一个ArrayList的ArrayList - 我用这种方式声明它:
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 :( 但是当我尝试在DataTable标签中使用它时,我什么也看不见:(
<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?
我应该如何在JSF中使用这个数组?
Ps this is my faces.config: 这是我的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 . 当我更改变量'i'并输入例如:4时,我在控制台上看到“something”。 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 ).
变量'colNumber'设置为5(但我的sql表有7列,我使用“select * from mytable”,所以我不认为这是一个反问题)。
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. 关于吞咽异常,除非你确切知道自己缺少什么,否则你应该在遇到异常时抛出异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.