Struts2中的预选单选按钮 [英] Preselect radio button in Struts2

查看:75
本文介绍了Struts2中的预选单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Struts2 ,我有一个非常简单的单选标签,如下所示

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 返回 2 。因此,我希望第二个单选按钮被预先选择,但是没有发生。我什至尝试过:

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}"/>

但这也不起作用。

我在做什么错了?

推荐答案

删除value属性从jsp。然后,在Java代码中,确保 correctAnswer变量具有所需的值。

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)

这篇关于Struts2中的预选单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆