Struts1 动态FormBean 类型问题

Silence_Smile 2010-07-16 01:32:34
Struts1中 如果页面中使用的是普通的html标签,则标签<input type="checkbox" name="f1"/> 在配置动态FormBean的时候属性f1应该配置成什么类型?怎么我配成String和Boolean都不行啊?checkbox选没选中都输出“on”
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun_s 2010-07-16
  • 打赏
  • 举报
回复
动态的formbean 应该是Sting类型的 因为他的值是String 类型的 只是他的属性 有selected 的属性 或者方法的 配置是String 类型的 看看你的程序处理的逻辑是不是有错的
closewbq 2010-07-16
  • 打赏
  • 举报
回复
配置文件中:
<form-property name= "checkbox" type= "java.lang.String[]"> </form-property>

Action中:
String[] items = (String[])form.get("checkbox");
Silence_Smile 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 epiphone 的回复:]

FORMBEAN 中定义
private String[] checkBox = {""};//这样可以避免一个都没有选中时的空引用
public String[] getCheckBox(){return this.checkBox ;}
public void setCheckBox( String[] checkBox){ this.checkBox = checkBox ;} ……
[/Quote]
如果是动态FormBean呢?
wj63558595 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 epiphone 的回复:]

FORMBEAN 中定义
private String[] checkBox = {""};//这样可以避免一个都没有选中时的空引用
public String[] getCheckBox(){return this.checkBox ;}
public void setCheckBox( String[] checkBox){ this.checkBox = checkBox ;} ……
[/Quote]

正解!checkbox的值是数组型的
Epiphone 2010-07-16
  • 打赏
  • 举报
回复
FORMBEAN 中定义
private String[] checkBox = {""};//这样可以避免一个都没有选中时的空引用
public String[] getCheckBox(){return this.checkBox ;}
public void setCheckBox( String[] checkBox){ this.checkBox = checkBox ;}

ACTION

for (int i=0;i <yourformbean.getCheckBox().length;i++) {
System.out.println(yourformbean.getCheckboxd()[i]);
}
Silence_Smile 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jiaping108 的回复:]

用String 就行
HTML code

<html>
<head>
<script language="javascript">
function setValue(){
if(document.all.f2.checked){
document.all.f1.value="1";
}
else{
document.all.f1.value="0";
}
}
</script>
</he……
[/Quote]
晕,这么搞我不如直接request.getParameter()算了
jiaping108 2010-07-16
  • 打赏
  • 举报
回复
用String 就行

<html>
<head>
<script language="javascript">
function setValue(){
if(document.all.f2.checked){
document.all.f1.value="1";
}
else{
document.all.f1.value="0";
}
}
</script>
</head>
<body>
<input type="checkbox" name="f2" onclick="setValue();"/>
<input type="hidden" name="f1" value="0"/>
</body>
</html>

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧