[英]JSF ResultSet in h:dataTable with dynamic columns
I am currently trying to display a ResultSet in ah:dataTable in JSF. 我目前正在尝试在JSF的ah:dataTable中显示ResultSet。
Basically what I am doing is executing a SQL statement which can be inserted on the website and I want to display the result of that in a table. 基本上,我正在执行的是一条可以插入网站的SQL语句,我想在表中显示该结果。 I can not create model classes because the tables that are used are also dynamic.
我无法创建模型类,因为所使用的表也是动态的。 The tricky part is the fact, that I do not know how many columns there are in the ResultSet, nor the datatypes(currently I am getting these from the ResultSetMetaData).
棘手的部分是事实,我不知道ResultSet中有多少列,也不知道数据类型(当前我是从ResultSetMetaData中获取这些列)。
How would I go about displaying something with dynamic columns and column content(different datatypes) in a table on a website using JSF? 如何使用JSF在网站的表格中显示带有动态列和列内容(不同数据类型)的内容?
Thanks in advance. 提前致谢。
Have a data structure like List<Map<String, Object>> results
in your managed bean to store the results. 在托管bean中具有类似于
List<Map<String, Object>> results
的数据结构以存储结果。 On UI side, use 2 nested ui:repeat
elements instead of an h:dataTable
. 在用户界面方面,请使用2个嵌套的
ui:repeat
元素代替h:dataTable
。 Outer repeat will loop rows ( results
), inner repeat will loop columns ( result.keySet()
), each cell will get its value by result.get(fieldName)
. 外部重复将循环行(
results
),内部重复将循环列( result.keySet()
),每个单元格将通过result.get(fieldName)
获得其值。
Not-tested UI code: 未经测试的UI代码:
<table>
<ui:repeat value="#{mb.results}" var="result">
<tr>
<ui:repeat value="#{result.keySet()}" var="fieldName">
<td>
#{result.get(fieldName)}
</td>
</ui:repeat>
</tr>
</ui:repeat>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.