使用特立尼达图表标签在 XHTML 中,但没有输出
下面是我遇到问题的代码,我没有得到图表的输出。 请帮助我。
我的 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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<h:body>
<h1>Director Screen</h1>
<tr:document>
<tr:form>
<tr:chart value="#{chartBean}" type="pie" />
<tr:chart value="#{chartBean}" type="bar" />
<tr:chart value="#{chartBean}" type="circularGauge">
</tr:form>
</tr:document>
</h:body>
</html>
Java 代码
package com;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.myfaces.trinidad.model.ChartModel;
@ManagedBean(name = "chartBean")
@SessionScoped
public class ChartBean extends ChartModel {
@Override
public List<String> getGroupLabels() {
List<String> groupLabels = new ArrayList<String>();
groupLabels.add("Java");
groupLabels.add("Linux");
groupLabels.add(".NET");
return groupLabels;
}
@Override
public List<String> getSeriesLabels() {
List<String> seriesLabels = new ArrayList<String>();
seriesLabels.add("Love it");
seriesLabels.add("Hate it");
return seriesLabels;
}
@Override
public List<List<Double>> getYValues() {
List<List<Double>> chartValues = new ArrayList<List<Double>>();
// Fill the groups
for (int i = 0; i < getGroupLabels().size(); i++) {
List<Double> numbers = new ArrayList<Double>();
// fill the series per group
for (int j = 0; j < getSeriesLabels().size(); j++) {
numbers.add(100* Math.random());
}
chartValues.add(numbers);
}
return chartValues;
}
}
Below is the code where i am facing the issue, i am not getting the output of the graphs.
Kindly help me.
My XHTML code
<?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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:tr="http://myfaces.apache.org/trinidad">
<h:body>
<h1>Director Screen</h1>
<tr:document>
<tr:form>
<tr:chart value="#{chartBean}" type="pie" />
<tr:chart value="#{chartBean}" type="bar" />
<tr:chart value="#{chartBean}" type="circularGauge">
</tr:form>
</tr:document>
</h:body>
</html>
Java Code
package com;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.apache.myfaces.trinidad.model.ChartModel;
@ManagedBean(name = "chartBean")
@SessionScoped
public class ChartBean extends ChartModel {
@Override
public List<String> getGroupLabels() {
List<String> groupLabels = new ArrayList<String>();
groupLabels.add("Java");
groupLabels.add("Linux");
groupLabels.add(".NET");
return groupLabels;
}
@Override
public List<String> getSeriesLabels() {
List<String> seriesLabels = new ArrayList<String>();
seriesLabels.add("Love it");
seriesLabels.add("Hate it");
return seriesLabels;
}
@Override
public List<List<Double>> getYValues() {
List<List<Double>> chartValues = new ArrayList<List<Double>>();
// Fill the groups
for (int i = 0; i < getGroupLabels().size(); i++) {
List<Double> numbers = new ArrayList<Double>();
// fill the series per group
for (int j = 0; j < getSeriesLabels().size(); j++) {
numbers.add(100* Math.random());
}
chartValues.add(numbers);
}
return chartValues;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
模板中必须在
之前添加
。这是所有 JSF 2.x 脚本和样式表结束的地方。如果
有一些 JS/CSS 依赖项,我不会感到惊讶。It's mandatory to have a
<h:head>
in the template right before<h:body>
. That's where all the JSF 2.x scripts and stylesheets end in. I won't be surprised if the<tr:chart>
has some JS/CSS dependencies.我无法在 xhtml 文件中获取图表,因此我在 jsp 中复制了相同的内容并获取了图表。
I was unable to get the graph in xhtml file, so i copied the same in jsp and got the graph.
我遇到了类似的问题,并通过将以下几行添加到 web.xml 来解决它:
I had a similar problem and solved it by adding the following lines to web.xml: