LoginSignup
5
5

More than 5 years have passed since last update.

PlayFramework2 (Java) Viewsでのメモ書き

Posted at

・scala.htmlから別のscala.htmlを参照する事ができる
例(
index.scala.html
<form action="/" method="get">
@formInputText("てすと","inputname",”初期値”)
@formInputText("おためし","otamesi",”最初に入力されてる文字だよ”)
</form>

formInputText.scala.html
@(title:String,name:String,default:String)
@title<input type="text" name="@name" value="@default">

これで、表示するとテキストフォームが2つ表示される

・viewでの配列の設定方法
scala.htmlはScalaでコンパイルされるから、Javaの文法で書くとエラーが出る
特に、配列の書き方がJavaと違うから注意する
引数としての設定方法
scala.html
@(options:Array[String])
@for(option <- options){
option
}

each-for文も少し違うから注意する

もし上記のファイルにviewが配列を送りたい場合は
Array("A","B","C")
のように書く(Javaと違うのはカッコが{}→()なのと"Array"を前につけるの必須)

5
5
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
5
5