2017-01-28 9 views
1

私はPlayフレームワークを学習しており、CRUDコントローラを学習しています。私は新しい投稿を追加するためのフォームを作成したいが、私はコンパイルエラーがある。私がスカラーに慣れていないので、私はエラーを理解することができません。Play Framework初心者。 Scala.htmlコンパイルエラー

@(productForm: Form[Product]) 
@import helper._ 
@import helper.twitterBootstrap._ 

@main("Product Form"){ 
<h1>Product Form</h1> 

@helper.form(action = routes.Products.save()){ 
    <fieldset> 
     <legend>Product (@productForm("name").valueOr("New")) </legend> 
     @helper.inputText(@productForm("ean"), '_label -> "EAN") 
     @helper.inputText(@productForm("name"), '_label -> "Name") 
     @helper.textarea(@productForm("description"), '_label -> "Description") 
    </fieldset> 

    <input type="submit" class="btn btn-primary" value="Save"> 
    <a class="btn" href="@routes.Products.index()">Cancel</a> 
} 
} 

エラーは次のとおりです。

/Users/andrei/Desktop/PlayFramework/app/views/products/details.scala.html:11: illegal start of simple expression 
[error]    @helper.inputText(@productForm("ean"), '_label -> "EAN") 

別の問題:私はクラスでプライベート静的最終変数を定義しますが、私はエラーを取得します。私は2014本からのフレームワークを学んでいて、それは非推奨のライブラリに起因することだと思う

import play.api.data.Form; 
import play.api.FormFactory; 
public class Products extends Controller { 

Form<Product> productForm = formFactory.form(Product.class); 

エラー:ドキュメントへ

cannot find symbol 
symbol: variable formFactory 
location: class controllers.Products 

ソース私がFormFactory見つけた: https://www.playframework.com/documentation/2.5.x/JavaForms

答えて

2

@で式を開始してから、productFormより前に使用する必要がないため、

@helper.inputText(productForm("ean"), '_label -> "EAN") 

はあなたのためのトリックを行う必要があります。

The Scala template uses @ as the single special character. Every time this character is encountered, it indicates the beginning of a dynamic statement. You are not required to explicitly close the code block - the end of the dynamic statement will be inferred from your code:

+0

ありがとうございます!これは私の問題を解決しました!あなたはその質問をチェックできますか?私は質問を更新してもう1つの問題を追加しました。おそらくあなたはそれを解決するのに役立つでしょう –

+0

@xzayt、別の質問を追加する必要があります。同じものに追加しない – Mysterion