Struts2: problem when assigning a value to a variable for a checkbox

I am working on struts2. In my jsp page, I want to assign the value of a string variable to a checkbox (when it is checked by the user). I have tried many times -

<% String code = "decompose"; %>

      

1)
<tr><td>
<s:checkbox name="codeCkBox" fieldValue="%{‘code’}" onclick="submit()"/> </td></tr>


2)
<tr><td>
<s:checkbox name="codeCkBox" value="%{‘code’}" onclick="submit()"/>
</td></tr>


3)
<tr><td>
<s:set name="setCkBoxValue" value="%{‘code’}"/>
<s:checkbox name="codeCkBox" fieldValue="# setCkBoxValue" onclick="submit()"/>
</td></tr>


But every time I tried to get this value by the name of the checkbox it returns the variable name ie "code". Looking for a solution. Thanks in advance.

0


a source to share


3 answers


Have you tried to do ${code}

instead ${'code'}

?



+1


a source


Do you have struts directive enabled? i ask because his only showing "code" which could mean he ignores racks



0


a source


<tr><td> <s:checkbox name="codeCkBox" value="%{#code}"
 onclick="submit()"/> </td></tr>

      

try the above code. since the code is a JSP variable, so it should be referenced in C # before its name and not with a quote. Hope it helps

0


a source







All Articles