解决。我真的不知道我做了什么,但它奏效了。其中一个时刻......
我的域名对象是“Actiune”。我想添加一个包含4个预设字段的新条目,其中另一个条目具有给定“idNewEtapa”方法的id。所以我查询该条目(带有id)并获取它的值,在表单和命中保存中预设它们但它不起作用。保存无效。
我做错了什么?我已经花了好几个小时了。请再次帮助stackOverflow:)
如果您不想查看所有代码,请告诉我这是怎么做的或者给我一个例子:)
THX!
这些是我的代码的相关部分
这是我的GSP表单:
<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()方法中print语句的输出 * ... 的* 参数[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,联系人:[id:1],termenPornire:date.struct,firma:Google,idActiune:zt8h,termenLimita_year:2012,action:save,controller: actiune] \ ....
in save ... [user: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]