我正在尝试在Facelets文件的表格中显示JSONObject
。我怎样才能做到这一点?
package com.myportal.dashboard;
import javax.annotation.PostConstruct;
import net.sf.json.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.web.context.WebApplicationContext;
@Component
@Scope(value=WebApplicationContext.SCOPE_SESSION)
public class DashboardBacker {
private JSONObject dashboardTable;
@PostConstruct
public void initializeTable() {
dashboardTable.put("Completed", 26);
dashboardTable.put("Failed", 33);
dashboardTable.put("In Progress", 44);
dashboardTable.put("On-hold", 9);
}
public JSONObject getDashboardGraphs() {
return dashboardGraphs;
}
}
答案 0 :(得分:1)
将json对象转换为字符串并将其设置为beans属性,如下所示:
String myJson = null; //getter / setter
@PostConstruct
public void initializeTable() {
....
myJson = dashboardGraphs.toString();
//myJson = new Gson().toJson(dashboardGraphs); //in case of Gson usage
}
比你的xhtml
然后在你的js代码中使用输入id $('#my-json-holder')来访问它.val()