Memoc
Memoc

Reputation: 303

GSP pass Array from controller and display in gsp by its index

how can I pass an array from controller to gsp, and view it by index in that gsp?

Lets say in controller:

String[] str= new String[2];
str[0]="A"
str[1]="B"

render(view: "test_preview",model:[flag:str])

and in gsp, how can i call let say index [1] value "B" specifically in the gsp without any looping possibly?

Upvotes: 1

Views: 883

Answers (1)

Jesús Iglesias
Jesús Iglesias

Reputation: 140

You can try this.

  1. You pass full array to view. And in your view, you do the following:

    ${flag[1]}
    
  2. Or: you only pass the specific value to view. In your controller:

    render(view: "test_preview",model:[flag:str[1])
    

    And in your view:

    ${flag}
    

Upvotes: 0

Related Questions