【问题标题】:Struts2 Iterator OGNL index not workingStruts2 Iterator OGNL 索引不起作用
【发布时间】:2013-03-17 00:44:25
【问题描述】:

我有这个迭代器。

<s:iterator value = "myQuestions"  status="key">

<s:property value="%{#key.index}" />
<h1><s:property value = "myQuestions[%{#key.index}].question"/></h1>

</s:iterator>

当迭代器对此进行迭代时

<s:property value="%{#key.index}" />

它显示正确的索引。但是当我在这个中添加%{#key.index}

 <h1><s:property value = "myQuestions[%{#key.index}].question"/></h1>

它不显示处于该特定索引的元素。

假设当前索引为 0。

当我这样做&lt;s:property value = "myQuestions[%{#key.index}].question"/&gt; 时,它不会显示任何内容。但是当我硬编码它时。

<s:property value = "myQuestions[0].question"/> it displays the proper item. what am I missing?

【问题讨论】:

    标签: java struts2 iterator jstl ognl


    【解决方案1】:

    你破坏了评估。它应该更接近:

    %{myQuestions[#key.index].question}
    

    不过,这很多余,因为您正在迭代,并且集合中的每个对象都将被推送到堆栈中,因此您只需引用 question

    如果您需要命名每个对象,也可以使用var 属性。

    考虑查看迭代器标签文档。

    【讨论】:

    • 我应该在哪里插入?
    • 当我重新提交表单时。它会重新填充列表吗?
    • @user962206 ... 在您尝试访问特定问题的唯一地方?
    • @user962206 什么形式?!您正在显示一个与表单无关的值。
    • 我会在另一个问题中问这个问题。把它放在这里是断章取义的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    相关资源
    最近更新 更多