How could the text field show the value stored in the `paramsText` when the checkbox is checked?

55 views Asked by At

I have a HashMap<String, String> in Struts2:

@In(scope=ScopeType.CONVERSATION)
@Out(scope=ScopeType.CONVERSATION)
private Map<String, String> paramMap;

and a String[]:

@In(scope=ScopeType.CONVERSATION)
@Out(scope=ScopeType.CONVERSATION)
private String[] paramsText;

the paramsText is used to store the value of paramMap, and in my jsp, I use <s: iterator> to display the paramMap and paramsText:

<s:iterator value="paramMap" var="param" status="paramsStatus">
<tr>
 <td>
 <input type="checkbox" key_id="<s:property value="#paramsStatus.index"/>" name="params" value="<s:property value="#param.key"/>"
 <s:iterator value="params" var="app">
  <s:if test="#app==#param.key">
  checked
  </s:if>
 </s:iterator>/>
 &emsp;<s:property value="#param.value"/>
 </td>

 <td>
 <input type="text" text_id="<s:property value="#paramsStatus.index"/>" name="paramsText" />
 </td>
</tr>

How could the text field show the value stored in the paramsText when the checkbox is checked? I'm thinking about the value property, how should I specify it?

1

There are 1 answers

3
Roman C On BEST ANSWER

The value in the paramsText you can get while iterating. You need to use <s:set> tag to store the value in the value stack.

<s:iterator value="params" var="app">
  <s:if test="#app==#param.key">
  checked
  <s:set var="paramsText" value="#param.value"/>
  </s:if>
</s:iterator>/>

<input type="text" text_id="<s:property value="#paramsStatus.index"/>" name="paramsText" value="<s:property value="#paramsText"/>">