提交 Struts2 迭代器索引作为映射键不起作用

Submitting Struts2 iterator index as a map key not working

我 运行 遇到了一个有趣的问题,但我无法真正弄清楚它是什么。

我有一个显示文本字段的 struts 迭代器。定义如下:

    <s:form action="AddSubmit" method="post" theme="simple">
        <s:iterator status="rowStatus" value="otherList">
                <div>
                   <span>Input Value:</span>
                   <s:textfield theme="simple" 
                        name="valueMap[%{#rowStatus.index} + '-custom'].inputValue"/>
                                    </div>
        </s:iterator>
        <s:submit value="Save" theme="simple" />
   </s:form>

当我提交时,迭代器值 %{#rowStatus.index} 不会计算任何值,并且该值永远不会设置,但是当我对 0 这样的键进行硬编码时,它会起作用。知道发生了什么事吗?

这应该有效:

name="%{'valueMap[\'' + #rowStatus.index + '-custom\'].inputValue'}"

%{ OGNL expression } 用于强制 OGNL 评估通常被解释为字符串文字的属性。