我有以下会话bean:
@Stateless
public class AuditDataRetriver {
@PersistenceContext
EntityManager em;
public String executeQuery() {
....
}
和模型:
@Model
public class ChartBean implements Serializable {
@Inject
AuditDataRetriver dataRetriver;
private CartesianChartModel linearModel;
public ChartBean() {
createLinearModel();
}
public CartesianChartModel getLinearModel() {
return linearModel;
}
private void createLinearModel() {
linearModel = new CartesianChartModel();
Map<String, List<StatisticsObj>> map = dataRetriver.executeQuery();
for (Map.Entry<String, List<StatisticsObj>> entry : map.entrySet()) {
String op = entry.getKey();
LineChartSeries series = new LineChartSeries();
series.setLabel(op);
List<StatisticsObj> list = entry.getValue();
for (StatisticsObj statisticsObj : list) {
series.set(statisticsObj.datetime, statisticsObj.value);
}
linearModel.addSeries(series);
}
}
....
}
因此,当你看到我在模型中注入会话bean时,我尝试通过
在JSF中使用该模型<?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:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets #{chartBean.linearModel}
</h:body>
</html>
但访问JSF ==&gt;
com.google.common.collect.ComputationException: java.lang.NullPointerException
at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:400)
at org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:163)
at org.jboss.weld.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:115)
at org.jboss.weld.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:188)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
at com.sun.el.parser.AstValue.getBase(AstValue.java:151)
at com.sun.el.parser.AstValue.getValue(AstValue.java:200)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
..... ..... .....
Caused by: java.lang.NullPointerException
at sep.tools.ChartBean.createLinearModel(ChartBean.java:40)
at sep.tools.ChartBean.<init>(ChartBean.java:27)
at sep.tools.ChartBean$Proxy$_$$_WeldClientProxy.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:374)
at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at org.jboss.weld.bean.proxy.ProxyFactory.create(ProxyFactory.java:262)
at org.jboss.weld.bean.proxy.ClientProxyFactory.create(ClientProxyFactory.java:103)
at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:157)
at org.jboss.weld.bean.proxy.ClientProxyProvider.createClientProxy(ClientProxyProvider.java:147)
at org.jboss.weld.bean.proxy.ClientProxyProvider.access$000(ClientProxyProvider.java:49)
at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:57)
at org.jboss.weld.bean.proxy.ClientProxyProvider$1.apply(ClientProxyProvider.java:53)
所以bean没有注入...... :(
感谢任何帮助
由于