假设这很简单,ArrayList<Integer>
您可以使用list()
.params
def myList = params.list('myList') //myList is the name in the view.
如果它是一个更复杂的列表,例如一个域类的列表,那么您需要使用命令。
Class A {
String name
}
Class ACommand {
List<A> listA = ListUtils.lazyList( [], FactoryUtils.instantiateFactory(A) )
}
看法
<g:hiddenField name="listA[0].name" value="Fisrt Name" />
<g:hiddenField name="listA[1].name" value="Second Name" />
绑定命令
class MyController {
def someAction() {
//in this example assume that this action is called in the submit of the form
ACommand command = new ACommand()
bindData(command, params) //this will populate the command with your list
}
}