我需要将一个 java 变量传递给一个 javascript 函数。我的代码如下。想知道这是正确的方法吗?
因为第一次加载页面时我在这里遇到了一些问题,并且单击了按钮,所以chartData和类别为空。
我期待以下内容:
chartData = [{"name":"Anne","data":[1.0,0.0,4.0]},
{"name":"Billy","data":[5.0,7.0,10000.0]}]
categories = ["APPLES","BANANAS","ORANGES"]
public String doLoadChartDataAction () {
String _cat = "[{\"name\":\"Anne\",\"data\":[1.0,0.0,4.0]},{\"name\":\"Billy\",\"data\":[5.0,7.0,10000.0]}]";
String _data = "[\"APPLES\",\"BANANAS\",\"ORANGES\"]";
System.out.println("1.0 " + " _cat:" + _cat);
System.out.println("1.0 " + " _data:" + _data);
setCategories(_cat);
setChartData(_data);
return "";
}
<p:commandButton styleClass="commandButton" value="This" id="btnThis" action="#{pc_Test.doLoadChartDataAction}"
oncomplete="renderChart('container','line','Sample Chart','${pc_Test.chartData}', '${pc_Test.categories}');">
</p:commandButton>