Grails表单提交仅适用于某些字段

时间:2016-05-18 09:40:07

标签: forms grails

Grails 3.1.6,以及使用grails-field-plugin构建的表单。尝试更新时,只更新字段集的一部分。用户控制器是脚手架。在这种情况下,只有字段"生日"和#34;国家"对更新做出反应。其他字段完全被忽略。如果我们从更新表单中删除这两个字段,则其余字段会定期响应更新请求。

这里是视图中引用形式的部分:

<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
}}

有关为什么会发生这种情况的任何想法?!

1 个答案:

答案 0 :(得分:0)

你能试试吗

<f:field property="firstName"/>

而不是

<f:field property="firstName">
     <g:textField name="firstName" value="${user?.firstName}"/>
</f:field>

虽然,我之前没有使用过这个插件。查看用法https://grails-fields-plugin.github.io/grails-fields/guide/usage.html

我认为不需要内部标签