Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COActually the reason i asked if i could use template was because its not just a plain text message. the message needs to be something like this- "property (id of property here) : (address of property here) has been added. this is why i created a template and i was wondering if i can render this template from my controller in my view.gsp- my template looks something like this- Property ${propertyInstance?.id} : ${propertyInstance?.address} has been added successfully
      singulars
    2. COWell I guess you could create a small template and pass it the propertyInstance. In that case you could embed the template in the view.gsp, and pass it the propertyInstance model. I'll add a small update to the answer. But that seems overly complicated - what you are showing the user is still just a plain text message. Unless there is something else that you haven't stated yet I would still do it as above - just make you flash.message="Property ${propertyInstance?.id} : ${propertyInstance?.address} has been added successfully"
      singulars
    3. COThanks for the edit, I'll explain why I'm choosing to go for the template instead of the flash message. It's because I want the message to be appended/displayed in the view every time the user enters new details, right below the old message. So if he has entered details 5 times, there should be 5 messages on the view page showing details of is properties. And the (street) has to be a link to take him to the list action(). I understand this is complicated. :(
      singulars
 

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