Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top