如何在h:inputText中设置Map值 [英] How to set a Map value in h:inputText
问题描述
我正在努力用JSF实现一个相当琐碎的功能,该功能涉及在页面上动态显示嵌套地图的内容并编辑其值的功能.但是事实证明,使用c:forEach
遍历地图时获得的MappedValueExpression$Entry
是不可写的!
I'm struggling to implement a fairly trivial functionality with JSF which involves dynamically displaying the content of a nested map on a page and editing capabilities for its values. But it has turned out that the MappedValueExpression$Entry
that you get when iterating over a map with c:forEach
is not writable!
<c:forEach items='#{inflectionBean.word.inflectionalForms}' var="number" >
<p:fieldset legend="#{number.key}">
<c:forEach items="#{number.value}" var="case" >
<p:panel header="#{case.key}">
<h:inputText value="#{case.value}" />
</p:panel>
</c:forEach>
</p:fieldset>
</c:forEach>
当我尝试提交上述表格时,我会得到:
When I am trying to submit the above form I'm getting:
javax.el.PropertyNotWritableException:/inflection.xhtml @ 39,56 value =#{case.value}":类'com.sun.faces.facelets.tag.jstl.core.MappedValueExpression $ Entry'确实可以没有可写的属性值".
javax.el.PropertyNotWritableException: /inflection.xhtml @39,56 value="#{case.value}": The class 'com.sun.faces.facelets.tag.jstl.core.MappedValueExpression$Entry' does not have a writable property 'value'.
我想知道是否有合理的解决方法,或者我是否以错误的方式解决了该问题.谢谢!
I wonder if there are reasonable workarounds or if I am approaching the problem in a wrong way. Thanks!
推荐答案
基本上,您的代码正在尝试调用 Map#put(key, value)
.
Basically, what your code is attempting is invoking Map.Entry#setValue(value)
. This is indeed not possible in EL. Instead, you should be referencing the map value directly on the map itself by key, so that EL can do Map#put(key, value)
.
<c:forEach items="#{number.value}" var="case">
...
<h:inputText value="#{number.value[case.key]}" />
这篇关于如何在h:inputText中设置Map值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!