I have a typical java string array String[] token = new String[20] in a controller.
I want to pass this array to .gsp file, where all the elements in token get printed out with a line break.
Wasn't too long before I figured that <g:each> should do exactly what needed. However, after attempting multiple options, nothing seems to have worked so far.
http://grails.org/doc/latest/ref/Tags/each.html This guide shows some examples, however, none of them seem to suit my need, because I need to read an array, not display different domain variables (and I actually tried them without luck).
Grails iterating in gsp vs. accessing Map elements This answer did not work
http://grails.1312388.n4.nabble.com/How-to-display-the-contents-of-a-string-Array-in-GSP-td1355405.html This at first seemed quite close to what I needed, however that also didn't work.
I've spent hours already on trying different combinations and variations of all those things. Every time it either results in an error or no elements get printed out. I know they are there, because if I ask for them specifically (just for one element), I can see results.
In my controller, I've tried passing the token with render view:'myFancy.gsp', model:['lsOut':token] and return [lsOut:token]. (Even return ['lsOut':token] just to be sure)
I'm out of ideas. Any suggestions on what to try next or what I could try again (because maybe I did some mistake)?
Controller:
def readContents()
{
String s = new RunSshCommand().execute() {
host = params.ServerAddress
username = params.Username
password = params.Password
command = "ls -m Funk"
}
String[] token = new String[20]
token = s.split(",")
//render view:'readContents.gsp', model:['i':token]
return [lsOut:token]
}
GSP file
<ul>
<g:each in="${token}" var="lsOut">
<td>${lsOut.value?.encodeAsHTML()}</td>
</g:each>
</ul>