Grails填充一个域实例 [英] Grails populating a domain instance
问题描述
我使用ag:formRemote标签来更新消息模板
< g:formRemote url =[action:'updateStatus']update =messagesname =updateStatusForm
onSuccess =document.updateStatusForm.message.value ='';>
< g:textArea name =messagevalue =cols =3rows =1/>< br />
< / g:formRemote>
然后这个表单在我的控制器中调用updateStatus方法
def updateStatus(String message){
def status = new Post(message:params.message,author:lookupPerson())
status.save flush:true,failOnError:true)
def messages = currentUserTimeline()
render template:'profileMessages',collection:messages,var:'profileMessage'
}
但是def状态行应该是
def status = new Post(message:params.message,author:lookupPerson(),child:Child.get(childInstance.id)
在我看来,我有一个childInstance这是由用户选择。是否有无论如何,我可以在控制器中保存一个全局变量,或者我可以发送子实例参数ID在formRemote标签,我认为没有,因为我一直试图这样做今天。
任何帮助都很好。我知道的唯一方法就是将childInstance.id写入一个属性文件并重新读入,但是必须有更好的方法,因为我认为这是非常糟糕的做法。
您可以将参数添加到< g:formRemote>
来自grails文档的示例:
< g:formRemote name =myFormupdate =updateMe
url =[controller:'book',action:'byAuthor',params:[sort:'title',order:'desc']]>
作者:< input name =authortype =text/>
< / g:formRemote>
I have been stuck for a couple of days on the same problem and I am not getting anywhere.
I am using a g:formRemote tag to update a messages template
<g:formRemote url="[action: 'updateStatus']" update="messages" name="updateStatusForm"
onSuccess="document.updateStatusForm.message.value='';">
<g:textArea name="message" value="" cols="3" rows="1"/><br/>
<g:submitButton name="Update Status"/>
</g:formRemote>
This form then calls a updateStatus method in my controller
def updateStatus(String message) {
def status = new Post(message: params.message, author: lookupPerson())
status.save(flush: true, failOnError: true)
def messages = currentUserTimeline()
render template: 'profileMessages', collection: messages, var: 'profileMessage'
}
But the def status line should be
def status = new Post(message: params.message, author: lookupPerson(), child: Child.get(childInstance.id)
In my view I have a childInstance which is the selected by the user. Is there anyway I can have a global variable in the controller which is saved or can I send the child instance params id in the formRemote tag. I don't think there is as i've been trying to do it this way all today.
Any help will be good. The only way I know will work will be to write the childInstance.id to a properties file and read it back in but there must be a better way as I think this would be very bad practice.
You can add params to <g:formRemote>
Example from the grails docs:
<g:formRemote name="myForm" update="updateMe"
url="[controller: 'book', action: 'byAuthor', params: [sort: 'title', order: 'desc']]">
Author: <input name="author" type="text" />
</g:formRemote>
这篇关于Grails填充一个域实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!