Grails webflow:将一组新的参数与现有的流变量合并

时间:2010-12-03 21:45:36

标签: grails spring-webflow

我正在尝试跨多个步骤填充域类。我无法将新的参数“合并”到现有的流量变量中。下面你将看到我目前是如何做到的(即从params对象单独设置域类字段)。

有更好的方法吗?

class UserController {
    def scaffold = User

    def index = {
        redirect(action:'registration')
    }
    def registrationFlow = {
        register1 {
            on("continue") {
                transient user = new User(params)
                flow.user = user
                if(!user.validate(['loginName', 'password'])) {
                    return error()
                }
            }.to "register2"
        }
        register2 {
            on("register") {
                transient user = flow.user;
                //TODO: is there a better way to merge the flow.user with the params?
                user.firstName = params.firstName;
                user.lastName = params.lastName;
                user.preferredEmail = params.preferredEmail;
                if(!user.validate()) {
                    return error()
                }
            }.to "registerFinal"
            on("return").to "register1"
        }
        registerFinal ()
    }
}

1 个答案:

答案 0 :(得分:0)

您可以为每页定义一个允许字段数组,并使用binddata:

限制这些字段名称
def validFieldsRegister2 = ["firstName", "lastName", "prefferedEmail"]
bindData(user, params,  [include: validFieldsRegister2])