Play Frameworkでの入力フォームについて、2.0以前では、自分でDouble型のフォーマットを書かなくちゃいけなくて面倒でしたが、2.1からはデフォルトでフォーマットが提供されるようです。
2.0の場合も、下記の実装をコピーしてフォーマッターを作れば簡単。
https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/data/format/Format.scala#L117
via http://stackoverflow.com/questions/12759430/play-bind-a-form-field-to-a-double
使い方
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import play.api._ | |
import play.api.data._ | |
import play.api.data.Forms._ | |
import play.api.data.format.Formats._ | |
val form = Form( | |
tuple( | |
"latitude" -> of[Doule], | |
"longitude" -> of[Double] | |
) | |
) | |
0 件のコメント:
コメントを投稿