如何在Javascript中访问Beans List of List

时间:2013-07-17 19:39:19

标签: java javascript jsf jsf-2 graphael

我正在使用Raphael图表和JSF 2.1。我正在尝试绘制一个线图,其中x轴的输入是一个数组数组,因此是y轴。我的x轴应包含时间戳(xhtml中的xvals),y轴应包含avgVal(xhtml中的avgbpsvals)。如何在javascript中访问TBA实例变量,如dt,avgVal? ui:repeat只给我结果bean。

    Class InputBean{
    private List<List<TBean>> results;
    private List<TBean> result;
private String resultJSON;
    //getters and setters
private String getResultJSON(){
Gson gson = new Gson();
return gson.toJson(results);
}
    }

Class TBean{
private Timestamp dt;
private Long avgVal;
//getters and setters
}

在sample.xhtml

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
    <h:head>
    <script type="text/javascript" src="/resources/js/raphael.js"></script>
            <script type="text/javascript" src="/resources/js/g.raphael.js"></script>
            <script type="text/javascript" src="/resources/js/g.line.js"></script>
            <script type="text/javascript" charset="utf-8">
    window.onload = function() {
                    var r = Raphael("holder", 1000, 1000);
    var results = #{inputTablePlot.resultJSON};
 for(var i=0; i &lt; results.length; i++)
                {
                    for(var j=0; j &lt; results[i].length; j++)
                    {
                        alert("j : " + j);
                        alert("value: " + results[i][j].avgVal);
                    }
                }
                    var lines = r.linechart(40, 30, 900, 900, xvals,
                            avgbpsvals, {
                                smooth : true,
                                symbol : 'circle',
                                axis : "0 0 1 1"
                            });
                    };

    </script>
    </h:head>
    <h:body>
    <h:panelGroup id="holder" layout="block"></h:panelGroup>
    </h:body>
    </f:view>
    </html>

0 个答案:

没有答案