Search code examples
javajspstruts2jstlognl

Runtime value population in Struts 2 textfield


I need to show list of text fields where number of textfields will be equal to number of element in the map and label should be key of the entry and value of textfield should be value corresponding to the key.

I attempted something like this:

<c:forEach var="score" items="${result.examscore}">
    <s:textfield label="%{score.key}" value="%{score.value}"></s:textfield>
</c:forEach>

I checked this code by hardcoding label and value's value. So, iteration is working fine, it is just a matter of populating values in textfields.


Solution

  • The variable score is not available in the value stack. Try

    <s:textfield label="%{#attr.score.key}" value="%{#attr.score.value}"></s:textfield>