如何在 jsf 中显示 hashmap 值? [英] How to show hashmap values in jsf?

查看:28
本文介绍了如何在 jsf 中显示 hashmap 值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 bean MyBean",它有属性 HashMap - map",它的值类型是 MyClass.我想使用 ui:repeat 在 jsf 中显示地图的一些属性.但是这些代码:

I have bean "MyBean", which has property HashMap - "map" which values type is MyClass. I want to show some properties of map in jsf using ui:repeat. But these code:

<ui:repeat  var="var"  value="#{mybean.map}" >
<tr> 
<td> <h:outputText value="#{var.value.property1}"></h:outputText> </td>
<td><h:outputText value="#{var.value.property2}"></h:outputText></td>
</tr>
</ui:repeat>

但是这段代码没有显示任何内容.虽然当我尝试以这种方式在 jsp 中显示 hashmap 值时,它是成功的.我哪里错了?以及如何解决?

But this code didn't show anything. Though when I try to show hashmap values in jsp this way, it was succesfull. Where I am wrong? And how fix that?

推荐答案

来自文档:

From the documentation for the repeat value attribute:

此标记迭代的项目集合的名称.集合可以是 List、数组、java.sql.ResultSet 或单独的 java Object.如果集合为空,则此标签不执行任何操作.

The name of a collection of items that this tag iterates over. The collection may be a List, array, java.sql.ResultSet, or an individual java Object. If the collection is null, this tag does nothing.

因此,var 被设置为您的 HashMap 并且 EL 尝试在其上查找键 "value".您需要将您的条目集公开为 List.

So, var is set as your HashMap and EL tries to look up the key "value" on it. You will need to expose your entry set as a List.

这篇关于如何在 jsf 中显示 hashmap 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆