无法取消选中Struts Multibox中的全部 [英] Can`t uncheck all in Struts Multibox

查看:97
本文介绍了无法取消选中Struts Multibox中的全部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在weblogic上的j2ee应用程序.我对多功能框感到困惑.

I have a j2ee application running on weblogic. I was confused with my multibox.

我对multibox的了解是,选中的项目将在提交时作为字符串数组传递.

What I know of multibox is that the checked items will be passed as an array of strings on submit.

我不知道为什么在我的应用程序中,当我取消选中一个或多个复选框时,只要一个复选框保持选中状态,它就可以正常工作,但是当我取消选中所有复选框时,提交的数组就是先前检查过的多复选框的数组应该是空的.

I don`t know why in my application it works fine when i uncheck a checkbox or more, as long as a single box remains checked but when I uncheck everything, the submitted array is the array of the previously checked multiboxes when it was supposed to be empty.

你能帮我吗?

推荐答案

您是否熟悉ActionForm类的reset()方法?

Are you familiar with the reset() method on the ActionForm class?

此方法的主要目的是重置复选框.如果您的表单中有一个选中的复选框,并且您提交了该复选框,那么该复选框将出现在请求中.如果未选中该复选框,则请求的内容将不会发送任何内容(GET提交是观察此行为的一种简单方法).

The purpose in life for this method is to reset checkboxes. If you have a checked checkbox in your form and you submit it, that checkbox will be on the request. If the checkbox is unchecked nothing will be sent on the request for it (a GET submit is a simple way to observe this behavior).

Struts执行请求绑定时,它按名称将请求中的参数与表单中的参数进行匹配.也就是说,如果有匹配项.

When Struts performs the request bind, it matches by name the parameters from the request to the parameters in the form. That is, if there is something to match.

现在考虑以下步骤:

  • 我在ActionForm上有一个布尔字段;
  • 我在表单中也有一个匹配的复选框;
  • 我提交表单=> Struts绑定了请求,所以现在我的属性在ActionForm中为true;
  • 我取消选中表单中的复选框,然后再次提交=>对该复选框的请求未发送任何内容=> Struts没有任何绑定=>您的字段在ActionForm上保持为真;

以上内容适用于多个复选框,但您得到的是数组,而不只是一个值.

The above applies for multi checkboxes, but you get an array instead of just one value.

输入reset()方法. Struts在绑定请求之前调用此方法.您可以在此处将字段值设置为false.如果到达请求,Struts会将其替换为true => OK.如果它没有到达请求(因为未选中),则该值将仍然为false =>再次确定.

Enter the reset() method. This is called by Struts before binding the request. Here you can set your field value to false. If it arrives in the request Struts will replace it with true => OK. If it does not arrive on the request (because it's unchecked) the value will remain false = > OK again.

多重框也是如此.您必须通过将数组的长度减少为零(但不能为null)来重置ActionForm中的值列表.

The same goes for multiboxes. You have to reset the list of values from the ActionForm by reducing the array to zero length (but not null).

如果您的ActionForm具有请求范围,则通常没有关系,因为在每次请求时都会重新创建对象.但是对于具有复选框的会话作用域的ActionForm,必须使用reset().

If your ActionForm has a request scope, it usualy does not matter because the object is recreated at each request. But for a session scoped ActionForm with checkboxes, reset() is a must.

这篇关于无法取消选中Struts Multibox中的全部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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