2016-03-30 11 views
0

私は、文字列プロパティtestPropertyを持つtestCompというコンポーネントを持っているとします。 testComp.javaに対応し、jsファイルです。testComp.jsタペストリー:対応するjavascriptファイルのページ/コンポーネントプロパティにアクセス

testComp.jsでtestPropにアクセスするにはどうすればよいですか?

次のように試しましたが、エラーが発生しています。

私はtmlファイルで$ {testProp}を実行できますが、javascriptファイルでこのプロパティにアクセスする必要があります。私はメーリングリストで検索しましたが、これまで運がありませんでした。どのようにそれを行うことができる任意のアイデア?

答えて

1

これを試してみてください:

testComp.javaを

@Inject 
private JavaScriptSupport javaScriptSupport; 

@AfterRender 
private void after() throws Exception { 
    JSONObject arguments = new JSONObject(); 
    arguments.put("testProperty", this.testProperty); 
    javaScriptSupport.addInitializerCall("testComp", arguments); 
} 

testComp.js

Tapestry.Initializer.testComp = function (json) { 
    new testComp(json); 
}; 


function testComp(json){ 
    alert(json.testProperty); 
} 
関連する問題