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

This is what I tried:

  <s:iterator var="tag" value="searchTagList">
    <s:property value="#tag"/>
    <s:textfield key="searchResults.#tag" name="#tag" value="#tag" />
  </s:iterator>

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.

有帮助吗?

解决方案

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

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top