Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: How to pass arrays to GSP pages

Tags:

grails

I need to display list of directories in GSP pages. Can you please guide me how to pass this array to GSP.

Here is my below sample code.

         File dir = new File(petl_dir_path)
          def list= []                      
          dir.eachDir{ list << it.name }       

Please guide

Thanks


1 Answers

Your 'list' is not an array, it's an instance of ArrayList. However, you can simply pass it to your view (in the following example, I assume you have the index action) like:

def index = {
  File dir = new File(petl_dir_path)
  def list= []                          
  dir.eachDir{ list << it.name }
  [dirs: list as String[]]
}

And then you can just process 'dirs' in your GSP.

like image 141
chanwit Avatar answered Nov 28 '25 01:11

chanwit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!