2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ScalatraでFormDataを受け取る(その2)

Posted at

前回、multiParamsで取るような配列の要素を送るときは...
なんて勿体ぶりまりましたが、要素がダブって設定されるという事象が生じます。

具体的には、

<form action="/file" method="post" enctype="multipart/form-data">
    <input type="text" name="datas" value="abc">
    <input type="text" name="datas" value="def">
    <input type="text" name="datas" value="123">
    <button value="submit">submit</button>
</form>

というようなformをpostした時に、
multiParams["datas"]で取得すると、

index 0:[abc]
index 1:[def]
index 2:[123]

という3つの要素の配列が取得できると思っていたのですが、

実際には

index 0:[abc]
index 1:[def]
index 2:[123]
index 3:[abc]
index 4:[def]
index 5:[123]

と要素の数が倍になってしまいました。

バグだったのでしょうが、とりあえずの対応としては、

配列の個数もリクエストパラメータにのせ、サーバ側でslice

というなんともはや、な処理をする必要がありました。
(checkboxとか面倒なことこの上なし)

後日談
何とかこのことを伝えたい、でも英語でissue書けないよ...と思ったところ、Scalatraのメンテナをされている瀬良さん(@seratch_ja)に辿り着き、いきなりメールを送りつけたにもかかわらず、対応してもらいました!

2.3、2.4系に取り込まれたみたいですね。
これでScalatraを使わない理由が1つ無くなりました。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?