简体   繁体   English

Struts 1如何设置复选框默认选中

[英]Struts 1 How to set checkbox default checked

I'm making some small changes to an existing project, which was built using Struts 1.2. 我正在对使用Struts 1.2构建的现有项目进行一些小的更改。 I need to have a check box on the form checked by default. 我需要在默认情况下选中的表单上有一个复选框。 I'm a newbie on Struts. 我是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. 我知道我无法在表单重置方法上为复选框设置默认值,实际上建议将重置方法中的复选框的值设置为false。 The only way I can think of is to check the POST param, but I don't think this is a good solution. 我能想到的唯一方法是检查POST参数,但我不认为这是一个很好的解决方案。

Is there a correct Struts way to have a default checked checkbox? 是否有正确的Struts方式来设置默认选中的复选框?

you have: 你有:

<html:checkbox property="multiRole" value="Y" />

if you want the page rendered with it checked by default, you need to set the property "multiRole" in your action form to "Y" 如果您希望默认选中使用它渲染的页面,则需要将操作表单中的属性“multiRole”设置为“Y”

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. 您还可以在最初显示表单的操作中设置值。

或者,您可以使用常规的“html标记来解决此问题。此标记还可以通过name参数与表单bean进行交互。在表单bean中,您可以使用布尔参数!

<input type="checkbox" name="multiRole" checked="checked" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM