因此,您要使用相同的表单和操作来创建(保存)和编辑(更新)?
您的save
根据保存是否成功,某个点的操作可以是redirect
或render
特定的视图。因为你总是希望呈现了同样的观点,无论它是否保存或不我这样做:
def save = {
def propertyInstance
//you need to do this since you are both saving and updating in the same action
if(params.id) {
propertyInstance = Property.get(params.id)
propertyInstance.properties = params
} else {
propertyInstance = new Property(params)
}
if (propertyInstance.save(flush: true)) {
flash.message="Property ${propertyInstance?.id} : ${propertyInstance?.address} has been added successfully"
}
else {
flash.message = "Please enter details again"
}
render(view: "view", model: [propertyInstance: propertyInstance])
}
,然后在view.gsp
你能证明你在flash.message
这样设置:
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
编辑
如果你想用一个模板(例如称为_addressMessage.gsp
),以显示与一些格式化的消息(比如如果地址的部分在单独的行),你可以做这样的事情在你的view.gsp
无论你想要的消息显示:
<g:if test="${propertyInstance.address}">
<g:render template="addressMessage" model="[propertyInstance: propertyInstance]" />
</g:if>
<g:else>
Please enter details again.
</g:else>
我包括在那里<g:if...
,因为我认为你不想显示这一点,如果没有地址。
我怀疑你会得到更多的帮助,直到你接受你已经给予的一些帮助。 – OnResolve 2012-07-17 22:47:12
该死的,对不起,我是这个网站的新手,真的不知道事情是如何完成的。 – niharika 2012-07-17 22:52:29
别担心,这是一个简单的修复;) – OnResolve 2012-07-17 22:53:38