Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Map value in h:inputText

Tags:

map

jsf

jstl

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!

like image 486
user1048677 Avatar asked Jul 31 '13 17:07

user1048677


1 Answers

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]}" />
like image 62
BalusC Avatar answered Oct 29 '22 01:10

BalusC