2011-10-22 13 views
2

にパラメータを渡す:プレイフレームワーク:私は<a href="http://www.playframework.org/documentation/1.2.3/templates#tags" rel="nofollow">custom Play! framework tag</a>にパラメータとしてフィールドの名前を渡したいカスタムタグ

#{ifError ${_field}} 
    <ul class="err"> 
    #{errors ${_field}} 
     <li>${error}</li> 
    #{/errors} 
    </ul> 
    #{/ifError} 

しかし、私が得るすべては例外です:

Template execution error (In /app/views/tags/errorList.html around line 1) 
Execution error occured in template /app/views/tags/errorList.html. Exception raised was MissingMethodException : No signature of method: Template_1008.$() is applicable for argument types: (Template_1008$_run_closure1_closure2) values: [[email protected]] Possible solutions: _(java.lang.String), is(java.lang.Object), run(), run(), any(), get(java.lang.String). 

play.exceptions.TemplateExecutionException: No signature of method: Template_1008.$() is applicable for argument types: (Template_1008$_run_closure1_closure2) values: [[email protected]] 

方法タグにパラメータを渡すことはできますか?

#{ifError _arg} 
    <ul class="err"> 
    #{errors _arg} 
    <li>${error}</li> 
    #{/errors} 
    </ul> 
#{/ifError} 

ますので、このテンプレートは、この#{errorList 'document.title' /}

答えて

2

のように呼ばれている:私は少し「Codemwnci」のソリューションを修正し、次のテンプレートコードになってしまっている

ソリューション

すでにタグ構文#{..}を使用してGroovyコードの一部に含まれている場合、Expression構文を使用する必要はありません(つまり、を使用する必要はありません構文)。

また、errorsタグでは入力が行われないため、フィールド名をエラータグに渡す必要があります。 errorタグの詳細については、this documentationを確認してください。

次はあなたのため

#{ifError _field} 
    <ul class="err"> 
    <li>#{error _field /}</li> 
    </ul> 
#{/ifError} 
+0

おかげで動作するはずです、それは働きます!単一の引数 'arg'のデフォルト名が使用されていない限り、名前付きパラメータをタグに渡すことが重要です。 Btw [エラーにはオプションパラメータがあります](http://www.playframework.org/documentation/1.2.3/tags#errors)。 – deamon

+0

です。それは知っていると便利です! – Codemwnci

関連する問題

 関連する問題