Search code examples
grailsgroovygsp

Output groovy list as comma separated string in gsp


I have the following in my controller:

render(view: "create", model: [dealInstance: dealInstance, storeName: params.storeName, location: params.location, openEmailClient: true, emailTo: users*.email])

And the following in my create.gsp:

$(document).ready(function () {

  <g:if test="${openEmailClient}">              
    <g:set var="subject" value="${g.message(code: 'deal.created.email.subject')}" scope="page" />
    <g:set var="body" value="${g.message(code: 'deal.created.email.body')}" scope="page" />
    window.location.href = "mailto:${emailTo}?subject=${subject}&body=${body}";
  </g:if>
});

This opens the default email client and populate the "To" field.

How can I convert the list of emails to a comma separated string? (Is this even correct? Will most email client accept a comma as the email separator?)

i.e. a@a.com,b@b.com...


Solution

  • Use the Groovy join method

    "mailto:${emailTo.join(',')}?....