Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So you are going to both create(save) and edit(update) using the same form and action? </p> <p>Your <code>save</code> action at some point will either <code>redirect</code> or <code>render</code> a particular view, based on whether the save was successful. Since you always want to render the same view regardless of whether it saves or not I would do this:</p> <pre><code>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]) } </code></pre> <p>And then in your <code>view.gsp</code> you can show what you set in the <code>flash.message</code> like this:</p> <pre><code> &lt;g:if test="${flash.message}"&gt; &lt;div class="message"&gt;${flash.message}&lt;/div&gt; &lt;/g:if&gt; </code></pre> <p><strong>EDIT</strong></p> <p>If you wanted to use a template (called <code>_addressMessage.gsp</code> for example) to show a message with some formatting (like the parts if of the address on separate lines) you could do something like this in your <code>view.gsp</code> wherever you wanted the message to show up:</p> <pre><code>&lt;g:if test="${propertyInstance.address}"&gt; &lt;g:render template="addressMessage" model="[propertyInstance: propertyInstance]" /&gt; &lt;/g:if&gt; &lt;g:else&gt; Please enter details again. &lt;/g:else&gt; </code></pre> <p>I included the <code>&lt;g:if...</code> in there since I think you don't want to show this if there is no address.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload