Grails:复选框未设置回false [英] Grails: checkbox not being set back to false

查看:19
本文介绍了Grails:复选框未设置回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Grails (1.0.4) 应用程序,我想在其中编辑网格视图中单个页面上的集合集合.我让它工作得很好,只取决于 Spring MVC 的索引参数处理,除了一件事:

I am developing a Grails (1.0.4) app where I want to edit a collection of collections on a single page in a grid view. I got it to work quite well depending only on the indexed parameter handling of Spring MVC, except for one thing:

网格中的布尔值(或者,就此而言,布尔值)可以通过复选框设置,但不能取消设置,即当我选中复选框并更新时,该值设置为 true,但之后当我再次编辑时,取消选中复选框并更新,它仍然是真实的.

boolean (or, for that matter, Boolean) values in the grid can be set via checkbox, but not unset, i.e. when I check the checkbox and update, the value is set to true, but afterwards when I edit again, uncheck the checkbox and update, it remains true.

这是复选框的 GSP 代码:

This is the GSP code of the checkbox:

<g:checkBox name="tage[${indexTag}].zuweisungen[${indexMitarb}].fixiert" value="${z.fixiert}" />

这是生成的 HTML:

And this is the HTML that is generated:

<input type="hidden" name="tage[0].zuweisungen[0]._fixiert" />
<input type="checkbox" name="tage[0].zuweisungen[0].fixiert" checked="checked" id="tage[0].zuweisungen[0].fixiert"  />

我发现了一个 Grails 错误,它准确地描述了这种效果,但它被标记在 1.0.2 中修复,并且那里描述的问题机制(隐藏字段名称中的下划线放在错误的位置)在我的情况下不存在.

I've found a Grails bug that describes exactly this effect, but it's marked as fixed in 1.0.2, and the problem mechanism described there (underscore in hidden field name is put in the wrong place) is not present in my case.

任何想法可能是什么原因?

Any ideas what could be the reason?

推荐答案

这是一个名叫 Julius Huang 的人在 grails-user 邮件列表中提出的解决方案.它是可重用的,但依赖 JavaScript 来填充带有false"响应的隐藏字段,用于 HTML 不幸未发送的未选中复选框.

This is the solution a guy named Julius Huang proposed on the grails-user mailing list. It's reusable but relies on JavaScript to populate a hidden field with the "false" response for an unchecked checkbox that HTML unfortunately does not send.

当我破解 GSP 时发送false"取消选中框 (true -> false)自定义标签库.

I hack GSP to send "false" when uncheck the box (true -> false) with custom TagLib.

默认情况下,checkBox 什么时候都不发送取消选中,所以我使用复选框事件处理程序但发送隐藏字段相反.

By default checkBox send nothing when uncheck, so I use the checkBox as event handler but send hidden field instead.

Controller 中的params"可以处理假"->真"没有任何修改.例如.一切都还在在控制器中相同.

"params" in Controller can handle "false" -> "true" without any modification. eg. Everything remain same in Controller.

GSP 中的自定义标签用法(示例 usedfunc_F 为true"),

The Custom Tag Usage in GSP (sample usedfunc_F is "true"),

<jh:checkBox name="surveyList[${i}].usedfunc_F" value="${survey.usedfunc_F}"></jh:checkBox>

这是标签生成的内容,

<input type="hidden" name="surveyList[#{i}].usedfunc_F" id="surveyList[#{i}].usedfunc_F" value="false" />
<input type="checkbox" onclick="jhtoggle('surveyList[#{i}].usedfunc_F')" checked="checked" />

Javascript

<script type="text/javascript">
function jhtoggle(obj) {
   var jht = document.getElementById(obj);
   jht.value = (jht.value !='true' ? 'true' : 'false');
}
</script>

这篇关于Grails:复选框未设置回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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