struts1标签- 使用注意事项

时间:2023-03-09 04:29:52
struts1标签-<html:radio> 使用注意事项

struts1标签-<html:radio> 使用注意事项

1、默认选中效果

  在后台XxxForm中写入如下代码,可保证默认选中效果实现:

@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
ve.setBuytaxisf("是");//是否免税交纳属性默认选中效果
super.reset(mapping, request);
}

  jsp代码:

<html:radio property="ve.buytaxisf" value="是">是</html:radio>
<html:radio property="ve.buytaxisf" value="否">否</html:radio>

  页面效果:struts1标签-<html:radio> 使用注意事项

  好处:1、不用设置默认值;2、页面选中效果自动实现。

  缺点:在action中接收并使用(XxxForm)xxxForm进行查询时,需将设置默认值的属性set为null,否则在查询条件(xxxForm对象)中包含默认值

2、禁用效果

<html:radio property="ve.buytaxisf" value="" style="display: none"></html:radio>
<html:radio property="ve.buytaxisf" value="是" disabled="true">是</html:radio>
<html:radio property="ve.buytaxisf" value="否" disabled="true">否</html:radio>

  页面效果:struts1标签-<html:radio> 使用注意事项

  注:测试发现,当把所有radio都设置成disabled,总会把第一个默认为可选,所以可以采用如上方法实现禁用效果