views:

1780

answers:

3

I am very new to grails.I am doing one sample project for image uploading and displaying.Right now my project uploads the images and stores into the images directory.Now i want to display all the images stored in the "image" directory. I dont know how to write the gsp code for display all images.

For displaying the images I wrote the following code in list.gsp page.

My gsp code is:

<g:each in="${imageList}" var="image">
<img src="${createLinkTo(dir: 'images', file: '1.jpg')}" alt="Grails"/>
</g:each>

imageList has filenames of images in the image directory.

In the second line i want put filename instead of "1.jpg".

Can any one tell me how to display the images.

thanks

+2  A: 

Depending on what's in your imageList, you can do a :

<g:each in="${imageList}" var="image">
<img src="${createLinkTo(dir: 'images', file: image.filename)}" alt="Grails"/>
</g:each>
mat
+2  A: 

Assuming your imageList is something like ['1.jpg', '2.jpg', ...], your createLinkTo should just look like:

${createLinkTo(dir: 'images', file: image)}

Since you've already defined the iterator variable as 'image'. If that doesn't work, it might help to clarify what's in the contents of your imageList collection.

Rob Hruska
+4  A: 

If your imageList has list of image objects try the following

${createLinkTo(dir: 'images', file: image.filename)}.

If your imageList like this['1.jpg','2.jpg','3.jpg'] try the following

**${createLinkTo(dir: 'images', file: image)}**