如何访问struts标签中的迭代器变量? [英] How to access iterator variable in struts tag?
问题描述
我正在遍历列表,并希望访问该值以创建文本输入字段.不幸的是,我无法访问<s:textfield>
标记内的循环变量
I'm looping over a list and want to access the value to create a text input field. Unfortunatley I'm failing to access the loop variable inside the <s:textfield>
tag
这是我尝试过的:
<s:iterator var="tag" value="searchTagList">
<s:property value="#tag"/>
<s:textfield key="searchResults.#tag" name="#tag" value="#tag" />
</s:iterator>
<s:property value="#tag"/>
被正确评估并显示循环变量.但是,永远不会评估<s:textfield>
中的#tag
.我还尝试将<s:property value="#tag"/>
代替#tag
而不成功.
The <s:property value="#tag"/>
is evaluated correctly and shows the loop variable. But the #tag
in the <s:textfield>
is never evaluated. I also tried to put <s:property value="#tag"/>
instead of #tag
without success.
推荐答案
使用了标签的key
属性,而不是三个name
,value
,label
.到目前为止,您已经定义了其中两个,就可以更改
The tag's key
attribute used instead of three ones name
,value
,label
. As far as two of them you have already defined, you can change
<s:textfield label="%{getText('searchResults.'+#tag)}" name="%{#tag}" />
该值由name
属性检索.您应该为在name属性中评估的名称提供一个吸气剂.请注意,如果您的操作扩展了ActionSupport
,则getText()
可用.而且,您必须在名称标签中强制进行名称评估.
The value is retrieved by the name
attribute. You should provide a getter for the name evaluated in the name attribute. Note, getText()
is available if your action extends ActionSupport
. And you have to force name evaluation in the name tag.
这篇关于如何访问struts标签中的迭代器变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!