views:

2439

answers:

2

Using Struts2, I have a very simple radio tag like following

    <s:radio label="correctOption" name="correctAnswer" list=" 
#{'1':'1','2':'2','3':'3','4':'4'}" value="questionVo.correctAnswer"/>

questionVo.correctAnswer returns 2. So I want the second radio button to be preselected but it is not happening. I even tried:

    <s:radio label="correctOption" name="correctAnswer" list=" 
#{'1':'1','2':'2','3':'3','4':'4'}" value="%{1}"/>

But that does not work either.

What am I doing wrong?

+1  A: 

Remove the value attribute from the jsp. Then in your Java code make sure that the "correctAnswer" variable has the value you want.

This has also the added effect that works in postbacks (when the user has selected something on the radio and the form is shown again)

kazanaki
A: 

It works for me for the following:

<s:radio 
  label="correctOption" 
  name="correctAnswer" 
  list="#{'1':'1','2':'2','3':'3','4':'4'}" 
  value="%{1}"/>
jenn wei