Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...