Preselect radio button in Struts2

。_饼干妹妹 提交于 2019-12-06 16:08:43

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)

jenn wei

It works for me for the following:

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

I believe that the issue is that the value needs to be escaped properly eg:

value="%{'1'}" 

and match the declaration exactly.

Here's the solution:

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

another one in case of strings in the static list:

<s:radio label="Gender" name="gender" list=" 
    #{'male':'Male','female':'Female'}" value="'male'"/>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!