因此,您要使用相同的表單和操作來創建(保存)和編輯(更新)?
您的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