复选框未选中时,struts checkbox标记提交的值 [英] What value is submitted by struts checkbox tag when checkbox is unselected

查看:357
本文介绍了复选框未选中时,struts checkbox标记提交的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到这种情况。

class MyForm extends IdSelectionForm {
  private Boolean approveIt = true;
  .....
}

我的JSTL表单包含



my JSTL form consists of

<html:checkbox property="approveIt" styleId="style1" value="true"/>

当我选择复选框并提交。在struts操作中,我获得为此字段设置的真实值。
再次当我取消选中并提交。然后我也得到真正的价值。我想知道它是否是默认值的东西。

When I select checkbox and submit. In struts action I get true value set for this field. And again when I uncheck it and submit. Then also I get true value. I am wondering if it is something with default value. Should it be overridden by false when I uncheck.

推荐答案

首先,< html:checkbox> ; 是Struts标记而不是JSTL标记。此标记仅生成复选框类型的标准HTML输入。和HTML复选框在检查时将其值作为参数值发送,并且在未选中时不发送任何参数。

First of all, <html:checkbox> is a Struts tag not a JSTL tag. This tag simply generates a standard HTML input of type checkbox. And HTML checkboxes send their value as parameter value when they're checked, and don't send any parameter when they're unchecked.

因此,由于默认值您的表单字段为true:

So, since the default value of your form field is true:


  • 如果选中复选框,Struts将会将其设置为true

  • 如果取消选中该复选框,它不会被Struts设置为任何内容,因此将保持其默认值:true

approveIt 属性的默认值应为false。这样,如果复选框未选中,它将保持其默认值(false),这是正确的。如果复选框被选中,它将被设置为true,这也是正确的。

The default value of the approveIt property should be false. That way, if the checkbox is unchecked, it will keep its default value (false), which is correct. And if the checkbox is checked, it will be set to true, which is also correct.

这篇关于复选框未选中时,struts checkbox标记提交的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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