我有一个级联下拉列表,可以在一个系统上正常工作,但在另一个系统上无法正常工作。 请参考下面的代码:.xhtml:
<p:selectOneMenu style="width: 150px" value="#{reportBean.exchange}">
<f:selectItem itemLabel="NSE" itemValue="nse"/>
<f:selectItem itemLabel="BSE" itemValue="bse"/>
<p:ajax update="sym" listener="#{reportBean.wow()}"/>
</p:selectOneMenu>
<h:outputText value="Scrip Symbol :"/>
<p:selectOneMenu value="#{reportBean.scripID}" id="sym" style="width: 100px">
<f:selectItem itemLabel="All" itemValue="0"/>
<f:selectItems var="scrip" value="#{reportBean.sl}" itemLabel="#{scrip.scripSymbol}" itemValue="#{scrip.scripID}"/>
</p:selectOneMenu>
不调用 wow() 方法,下面是 Bean 代码:
@javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
public class reportBean implements Serializable {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
transient private StatelessWebService_Service service ;
private java.util.List<service.MasterScrip> getAllScripByExchange(java.lang.String exchange) {
service.StatelessWebService port = service.getStatelessWebServicePort();
return port.getAllScripByExchange(exchange);
}
public void wow()
{
sl=getAllScripByExchange(exchange);
}
我调试了,发现调试点上线了
service.StatelessWebService port = service.getStatelessWebServicePort();
并进入 InvocationTargetException.java并转到以下方法:
public InvocationTargetException(Throwable target) {
super((Throwable)null); // Disallow initCause
this.target = target;
}
最后在Glassfish中返回的错误是:
WARNING: /ClientTemplate/tradeReport.xhtml @17,74 listener="#{reportBean.wow()}": java.lang.NullPointerException
javax.el.ELException: /ClientTemplate/tradeReport.xhtml @17,74 listener="#{reportBean.wow()}": java.lang.NullPointerException
在 managd Bean 中,如果我不实现可序列化,或者如果我不使服务成为瞬态,那么我就会得到 NotSerializable 异常。此错误的原因是什么?我该如何解决?编辑:
服务豆:
@ManagedBean
@javax.faces.bean.RequestScoped
public class serviceBean{
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
private StatelessWebService_Service service;
@ManagedProperty("#{reportBean}")
private reportBean reportBean;
public beans.reportBean getReportBean() {
return reportBean;
}
public void setReportBean(beans.reportBean reportBean) {
this.reportBean = reportBean;
} //other props
public String getExchange() {
return exchange;
}
public void setExchange(String exchange) {
this.exchange = exchange;
}
public void wow()
{
reportBean.setSl(getAllScripByExchange(reportBean.getExchange()));
}
报告豆:
@javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
public class reportBean implements Serializable {
private Integer scripID;
private String exchange;
private List<service.TradeStock> tradeList;
private List<MasterScrip> sl; //get set
现在我收到以下错误:
SEVERE: Error Rendering View[/ClientTemplate/tradeReport.xhtml]
javax.faces.FacesException: java.io.NotSerializableException: service.MasterScrip
将服务调用和操作方法拆分为不同的请求作用域 Bean 类。 将剩余的保留在视图作用域的 Bean 中。最后,在逐个作用域的请求中注入作用域为 1 的视图 @ManagedProperty
。
@ManagedBean
@RequestScoped
public class ReportActionBean {
@WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
private StatelessWebService_Service service;
@ManagedProperty("#{reportDataBean}")
private ReportDataBean reportDataBean;
// ...
}