Struts 1 如何设置复选框默认选中
我正在对使用 Struts 1.2 构建的现有项目进行一些小的更改。我需要默认选中表单上的复选框。我是 Struts 的新手。
据我所知,我无法为表单重置方法中的复选框设置默认值,实际上建议将重置方法中的复选框的值设置为 false。我能想到的唯一方法是检查 POST 参数,但我认为这不是一个好的解决方案。
是否有正确的 Struts 方法来默认选中复选框?
I'm making some small changes to an existing project, which was built using Struts 1.2. I need to have a check box on the form checked by default. I'm a newbie on Struts.
I understand that I can't set a default value for check boxes on form reset method, in fact it is suggested to set the value to false for checkboxes in reset method. The only way I can think of is to check the POST param, but I don't think this is a good solution.
Is there a correct Struts way to have a default checked checkbox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您有:
如果您希望默认选中该选项来呈现页面,则需要将操作表单中的属性“multiRole”设置为“Y”
you have:
if you want the page rendered with it checked by default, you need to set the property "multiRole" in your action form to "Y"
为什么不能在reset中设置默认值?这主要是它的用途。您还可以在最初显示表单的操作中设置一个值。
Why can't you set a default value in reset? That's mostly what it's for. You can also set a value in the action that initially displays the form.
或者,您可以使用 ,,normal" html 标签来解决此问题。该标签还可以通过 name 参数与表单 bean 交互。
在表单 bean 中,您可以使用布尔参数!
alternatively you can use the ,,normal" html tag to solve this problem. This tag can also interact with the form bean via the name parameter.
In the form bean you can use a boolean parameter!