Grails 复选框总是错误的
Grails checkbox always false
第一次在 Grails 中使用复选框。我想让复选框做的只是在选中时将布尔变量设置为 true。
来自form.gsp:
<div class="form-group col-md-12 ${hasErrors(bean: apiInstance, field: 'oneWay', 'error')} ">
<label for="oneWay">
<g:message code="api.oneway.label" default="One Way" />
</label>
<g:checkBox name="oneWay " value="true" checked="${apiInstance?.oneWay == 'true'}"/>
</div>
在我的域中 class 我定义了这个:
Boolean oneWay = false
在从控制器调用的服务中,我检查了 oneWay 的状态:
if (apiInstance.oneWay == true) {
log.info("One way flag is set.")
} else {
log.info("One way flag is not set.")
}
即使我选中了复选框,它也总是错误的。我犯了什么愚蠢的行为? :D
我认为您不需要使用 value 和 checked 属性,只需使用像这样的值:
<g:checkBox name="oneWay " value="${apiInstance?.oneWay}" />
第一次在 Grails 中使用复选框。我想让复选框做的只是在选中时将布尔变量设置为 true。
来自form.gsp:
<div class="form-group col-md-12 ${hasErrors(bean: apiInstance, field: 'oneWay', 'error')} ">
<label for="oneWay">
<g:message code="api.oneway.label" default="One Way" />
</label>
<g:checkBox name="oneWay " value="true" checked="${apiInstance?.oneWay == 'true'}"/>
</div>
在我的域中 class 我定义了这个:
Boolean oneWay = false
在从控制器调用的服务中,我检查了 oneWay 的状态:
if (apiInstance.oneWay == true) {
log.info("One way flag is set.")
} else {
log.info("One way flag is not set.")
}
即使我选中了复选框,它也总是错误的。我犯了什么愚蠢的行为? :D
我认为您不需要使用 value 和 checked 属性,只需使用像这样的值:
<g:checkBox name="oneWay " value="${apiInstance?.oneWay}" />