tags:

views:

981

answers:

2

Hi All, 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 user). I tried it many times like -

<% 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 everytime when I tried to get this value by checkbox name it returns variable name i.e “code”. Looking for a solution. Thanks in advance.

A: 

Hi!

Have you tried doing ${code} instead of ${'code'}?

Pablo Fernandez
Hi Pablo Fernandez,I tried both ${code} and ${'code'} and this time its throwing an exception i.e "According to TLD or attribute directive in tag file, attribute fieldValue does not accept any expressions". Any other solution ?
vivmal
Did it work? I ask because you accepted it
Pablo Fernandez
Pablo Fernandez , Its working but I did it differently. See my jsp snippet-String userId = "58835";request.setAttribute("userId ", userId );<s:checkbox name="ckbox1" fieldValue="%{#request.userId }"/>Thanks for your post.
vivmal
A: 
Johhny