私はこの Scala Play アプリケーションに取り組んでおり、少し調べて考えた後、ビューで使用されるレベル (または適用される最上位レベル) のフォーム パッケージの下にすべてのフォームを配置する設計を支持することにしました。
app
| views
| account
| form (all Form used by account will be here)
| PasswordChangeForm.scala
次に、PasswordChangeForm.scala
フォームは次のように実装されます。
package views.account.form
import play.api.data.Form
import play.api.data.Forms.{mapping, text}
import play.api.i18n.Messages
case class PasswordChange(password: String, repeatPassword: String)
object PasswordChangeForm {
val Instance = Form {
mapping(
"password" -> text(minLength = 5),
"repeatPassword" -> text(minLength = 5)
)(PasswordChange.apply)(PasswordChange.unapply).
verifying(Messages("playauthenticate.change_password.error.passwords_not_same"),
data => data.password != null && !data.password.isEmpty && data.password.equals(data.repeatPassword))
}
}
問題は、エラー報告用のフォームをどのように作成Messages
または利用できるようにするかがわかりません。MessagesApi
コンパイラ エラーは予想どおりcould not find implicit value for parameter messages: play.api.i18n.Messages
です。
[error] /home/bravegag/code/play-authenticate-usage-scala/app/views/account/form/PasswordChangeForm.scala:15: could not find implicit value for parameter messages: play.api.i18n.Messages
[error] verifying(Messages("playauthenticate.change_password.error.passwords_not_same"),
更新上記のソリューションを次からリファクタリングする可能性があります。
val Instance = Form {
に
def create(implicit messages: Messages) = Form {
Form
ただし、毎回の新しいインスタンスが作成されます。