-1
Grails 3.1.6和使用grails-field-plugin构建表单。尝试更新时仅更新字段集的一部分。用户控制器是脚手架的。在这种情况下,只有字段“生日”和“国家”对更新作出反应。其他领域完全被忽略。如果我们从更新表单中删除这两个字段,其余字段会定期对更新请求做出反应。Grails表单仅提交某些字段的作品
这里所指形式的视图的一部分:
<g:form resource="${this.user}" method="PUT">
<g:hiddenField name="version" value="${this.user?.version}"/>
<fieldset class="form">
<f:with bean="user">
<f:field property="firstName">
<g:textField name="firstName" value="${user?.firstName}"/>
</f:field>
<f:field property="lastName">
<g:textField name="lastName" value="${user?.lastName}"/>
</f:field>
<f:field property="birthday">
<g:datePicker name="birthday" precision="day" value="${user?.birthday}"
years="${2016..1900}" default="${user?.birthday}"/>
</f:field>
<f:field property="country">
<g:countrySelect name="country" value="${user?.country}"
noSelection="['': '-Choose your country-']"
default="${user?.country}"/>
</f:field>
<f:field property="address">
<g:textField name="address" value="${user?.address}"/>
</f:field>
</f:with>
</fieldset>
<fieldset class="buttons">
<input class="save" type="submit"
value="${message(code: 'default.button.update.label', default: 'Update')}"/>
</fieldset>
</g:form>
在此,用户域类
class User {
String firstName
String lastName
String email
String password
Date birthday
String country
String address
static constraints = {
firstName blank: false
lastName blank: false
email email: true, blank: false
password blank: false, size: 5..15, matches: /[\S]+/
birthday max: new Date()
country nullable: true
address nullable: true
}}
任何关于为什么会这样的想法?
感谢答案。解决,内部标签不是一个问题itsef。重要的是,外部和内部标签中的属性名称应该是相同的,否则整个字段集合会被打破。在我在这里发布的.gsp文件中,在“国家”和“生日”字段中,两个标签都指向相同的属性名称。所以可以这样,但在我测试的编辑器中,“country”的内部标签指的是“user.country”属性,而外部指的是“country”属性。这会导致我提到的错误行为。 – florigo