Sentil
Sentil

Reputation:

Grails: How to pass arrays to GSP pages

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

Upvotes: 3

Views: 3954

Answers (1)

chanwit
chanwit

Reputation: 3214

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.

Upvotes: 6

Related Questions