Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a collection/array parameters to an Action

I am reading the documentation about the controller http://www.playframework.org/documentation/1.1/controllers and I know how to define them on the controller side.

public static void show(Long[] id) {
    ...
}
or:

public static void show(List<Long> id) {
    ...
}
or:

public static void show(Set<Long> id) {
    ...
}

Now, how do I call the controller and pass the array ? I tried

Application/show?id=1,2,3,4 

it doesn't work

like image 605
Olivier Refalo Avatar asked Nov 12 '10 03:11

Olivier Refalo


2 Answers

The simplest way is

Application/show?id=1&id=2&id=3&id=4 

There is also a solution using @As annotation for custom binding since 1.1:

http://www.playframework.org/documentation/1.1/releasenotes-1.1#play.data.binding.As

like image 128
Guillaume Bort Avatar answered Nov 23 '22 09:11

Guillaume Bort


You pass them as normal HTTP parameters

Application/show?id[0]=1&id[1]=2&id[2]=3&id[3]=4
like image 31
Codemwnci Avatar answered Nov 23 '22 08:11

Codemwnci