0

解决了。我真的不知道我做了什么,但它奏效了。那些时刻之一...

我的域对象是“Actiune”。我想从另一个条目中添加一个具有 4 个预设字段的新条目,该条目具有给定的 id 到“createNewEtapa”方法。所以我查询那个条目(带有id)并获取它的值,在表单中预设它们并点击保存,但它不起作用。保存将不起作用。

我究竟做错了什么 ?我已经在这附近转了几个小时了。请再次帮助stackOverflow :)

如果您不想检查所有代码,请告诉我这是如何完成的或链接我一个示例:)

谢谢!

这些是我的代码的相关部分

这是我的普惠制表格:

<g:form action="save" enctype="multipart/form-data">

                <fieldset class="form">

                    <g:applyLayout name="form">
                        <tmpl:/templates/form />
                    </g:applyLayout>
                </fieldset>

                <fieldset class="buttons">

                    <g:submitButton name="create" class="save"
                        value="${message(code: 'default.button.adauga.label', default: 'Adauga')}" />
                    <g:actionSubmit name="create" class="save" action="savenew" value="Adauga2" />

                </fieldset>
            </g:form>

这是我的控制器:

def create(Long id){
def actiuneInstance = Actiune.findById(id)
def c = Actiune.createCriteria()
def instanceList = c {
    eq("idActiune", actiuneInstance.idActiune)
    order("termenPornire", "asc")
}

params.idActiune = actiuneInstance.idActiune
params.tema = actiuneInstance.tema
params.firma = actiuneInstance.firma
params.user = User.findById(springSecurityService.currentUser.id)

[instance: new Actiune(params)]
}

def save() {
def actiuneInstance = new Actiune(params)
actiuneInstance.user = User.findById(springSecurityService.currentUser.id)
actiuneInstance.termenPornire = new Date()

def actiuneBD = Actiune.findByIdActiune(params.idActiune)
actiuneInstance.idActiune = actiuneBD.idActiune
actiuneInstance.tema = actiuneBD.tema
actiuneInstance.firma = actiuneBD.firma

print "in params  " + params
print "\\"
print "in save...       " + actiuneInstance.properties

   if (!actiuneInstance.save(flush: true)) {
        render(view: "create", model: [firInstance: actiuneInstance])
        return
    }
flash.message = message(code: 'default.created.message', args: [message(code: 'actiune.label', default: 'Actiune'), actiuneInstance.idActiune])
redirect(action: "completeShow", id: actiuneInstance.id)
}

这是 save() 方法中打印语句的输出 * ... * 在 params [termenLimita_month:11, termenPornire_month:11, termenPornire_day:1, documentPath:, tema:Promotie A, termenLimita_day:1, _action_savenew:Adauga2, id:, observatii:uuu, termenLimita:date.struct, termenPornire_year:2012, etapa.id:1, etapa:[id:1], contact.id:1, contact:[id:1], termenPornire:date.struct ,公司:谷歌,idActiune:zt8h,termenLimita_year:2012,行动:保存,控制器:actiune] \ ....

在保存... [用户:Flavian,termenPornire:Thu Nov 01 22:57:45 EET 2012,contact:null,documentPath:null,temaId:1,etapaId:null,firmaId:3,firma:Google,contactId:null , termenLimita:null, idActiune:zt8h, observatii:null, userId:null, etapa:null, tema:Promotie A]

4

1 回答 1

0

调用actiuneInstance.validate()然后查看actiuneInstance.errors对象以查看对象上任何验证错误的结果。

于 2012-11-01T21:41:58.473 回答