Multiple flash.message per request

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple flash.message per request

elarex
Hi there

I'm rather hoping I'm missing a silly trick somewhere along the line...

I'm trying to send back a multi-line flash.message from my controller.

\n are ignored
<br/> are rendered verbatim

From what I can find, this is only meant to pass back a single status/message line. However, my controller action is processing a batch of items and I'd like to report back on each individually.

regards
Reply | Threaded
Open this post in threaded view
|

Re: Multiple flash.message per request

Ian Roberts
On 20/12/2010 11:18, elarex wrote:
>
> Hi there
>
> I'm rather hoping I'm missing a silly trick somewhere along the line...
>
> I'm trying to send back a multi-line flash.message from my controller.

The flash is just a map, you can put anything you like into it as long
as the next request's controller and/or views know what to do with the
value.  For example:

def statuses = []
items.each {
  //...
  statuses << "Success"
}
flash.itemStatuses = statuses

....

<g:if test="flash.itemStatuses">
  <ul>
    <g:each in="flash.itemStatuses"><li>${it}</li></g:each>
  </ul>
</g:if>

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Multiple flash.message per request

marcopas
Great tip! I am not using it like this, but still it might be useful in the future.

- Marco

On Dec 20, 2010, at 12:29 PM, Ian Roberts wrote:

> On 20/12/2010 11:18, elarex wrote:
>>
>> Hi there
>>
>> I'm rather hoping I'm missing a silly trick somewhere along the line...
>>
>> I'm trying to send back a multi-line flash.message from my controller.
>
> The flash is just a map, you can put anything you like into it as long
> as the next request's controller and/or views know what to do with the
> value.  For example:
>
> def statuses = []
> items.each {
>  //...
>  statuses << "Success"
> }
> flash.itemStatuses = statuses
>
> ....
>
> <g:if test="flash.itemStatuses">
>  <ul>
>    <g:each in="flash.itemStatuses"><li>${it}</li></g:each>
>  </ul>
> </g:if>
>
> Ian
>
> --
> Ian Roberts               | Department of Computer Science
> [hidden email]  | University of Sheffield, UK
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Multiple flash.message per request

elarex
In reply to this post by Ian Roberts
Thanks, it's actually painfully obvious if you explain it that way :)

I am used to using my scaffolded views which simply make use of flash.message. I'll change the scaffold to use multiple set if it's present (messages vs message).

Again, thanks for the tip.

Ian Roberts wrote
On 20/12/2010 11:18, elarex wrote:
>
> Hi there
>
> I'm rather hoping I'm missing a silly trick somewhere along the line...
>
> I'm trying to send back a multi-line flash.message from my controller.

The flash is just a map, you can put anything you like into it as long
as the next request's controller and/or views know what to do with the
value.  For example:

def statuses = []
items.each {
  //...
  statuses << "Success"
}
flash.itemStatuses = statuses

....

<g:if test="flash.itemStatuses">
  <ul>
    <g:each in="flash.itemStatuses"><li>${it}</li></g:each>
  </ul>
</g:if>

Ian

--
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email