Some Guy
Some Guy

Reputation: 239

Submitting array/list/seq via POST in play 1.2.4 with scala 0.9.1

I've only been able to find examples in java, and they all seem to suggest that what I am doing should "just work". I have a form like the following (either with the name as "id" or "id[]", both give the same results). I have tried declaring my edit method as taking List[Int] or Seq[Int], but in both cases id ends up being NULL. If I dump params, I can see that body does in fact contain the correct query string, and if I just do a get("id") it comes back as an int containing the first value (1). How can I get some sort of ordered container (don't care if it is a list or seq or whatever) submitted through a form?

<form method="post" action="">
    <input type="hidden" name="id" value="1" />
    <input type="hidden" name="id" value="2" />
    <input type="hidden" name="id" value="3" />
    <input type="hidden" name="id" value="4" />
    <input type="text" name="name" />
    <input type="submit" />
</form>

def edit(id: List[Int]) = {...}

Upvotes: 1

Views: 963

Answers (1)

Some Guy
Some Guy

Reputation: 239

Play doesn't handle scala collection types from forms, only java collections. Leaving the form as-is but changing the method to:

def edit(id: java.util.List[Int]) = {...}

Solves the problem. Then you can convert your java list into a scala list and use it normally.

Upvotes: 1

Related Questions