How to set a Map value in h:inputText

笑着哭i 提交于 2020-01-10 04:12:23

问题


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}": 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!


回答1:


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]}" />


来源:https://stackoverflow.com/questions/17977578/how-to-set-a-map-value-in-hinputtext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!