[英]How to set a Map value in h:inputText
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. 我正在努力用JSF实现一个相当简单的功能,它涉及在页面上动态显示嵌套地图的内容并编辑其值的功能。 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
迭代地图时得到的MappedValueExpression$Entry
是不可写的!
<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}": The class 'com.sun.faces.facelets.tag.jstl.core.MappedValueExpression$Entry' does not have a writable property 'value'.
javax.el.PropertyNotWritableException:/inflection.xhtml @ 39,56 value =“#{case.value}”:类'com.sun.faces.facelets.tag.jstl.core.MappedValueExpression $ Entry'没有可写财产'价值'。
I wonder if there are reasonable workarounds or if I am approaching the problem in a wrong way. 我想知道是否有合理的解决方法,或者我是否以错误的方式处理问题。 Thanks!
谢谢!
Basically, what your code is attempting is invoking Map.Entry#setValue(value)
. 基本上,您的代码正在尝试调用
Map.Entry#setValue(value)
。 This is indeed not possible in EL. 这在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)
. 相反,您应该通过键直接在地图上引用地图值,以便EL可以执行
Map#put(key, value)
。
<c:forEach items="#{number.value}" var="case">
...
<h:inputText value="#{number.value[case.key]}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.