【发布时间】:2013-01-16 16:36:28
【问题描述】:
我正在尝试在 jboss seam 2 项目中使用 google 可视化 api。
我创建了一个简单的例子,实际上取自Google Quick Start page。
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
当我在网络浏览器中将其作为文件打开时,它运行良好。但是当我将它放到我的 Jboss Seam 2 项目中并在 Web 浏览器中打开时,它会在红色背景上生成错误消息“b[c] is undefined”。
这是我在浏览器中打开页面源代码时看到的内容:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="/MCMS/a4j/g/3_3_3.Final/org/ajax4jsf/framework.pack.js" type="text/javascript"></script>
<script src="/MCMS/a4j/g/3_3_3.Final/org/richfaces/ui.pack.js" type="text/javascript"></script>
<link class="component" href="/MCMS/a4j/s/3_3_3.Final/org/richfaces/skin.xcss/DATB/eAGTKJ8eErp8hjQADcsDKg__" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
// Set chart options
var options = {'title':'How Much Pizza I Ate Last Night',
'width':400,
'height':300};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div"></div>
</body>
</html>
如您所见,Jboss Seam 为 a4j 添加了一些其他脚本 src。
a4j javascript 是否可能与 google 可视化 api javascript 冲突?
有没有办法解决这个问题?
【问题讨论】:
-
如果您删除 google 代码并仅添加一些标准 HTML,它是否可以正常工作? (即可能是其他软件包之一中的错误?)
-
是的。它无需谷歌代码即可工作。其他包中不可能有错误,因为它已经是一个长期存在的项目,Jboss Seam(+丰富的面孔)的所有功能都可以很好地工作。现在我们想在里面使用谷歌可视化来显示一些图表。
-
我还发现一个人在 JSF webapp groups.google.com/forum/#!topic/google-visualization-api/… 中也有类似的问题
标签: google-visualization jboss-seam