tags:

views:

953

answers:

1

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

+3  A: 

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.

chanwit
Why cast/coerce the list into a String array?
Daniel Rinser
Because the question asked about passing an array. I also wanted to show that his understanding of a List and an array is not fully correct.
chanwit