Reputation:
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
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