-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