我有app.xhtml,有一个数据表和面板。我正在使用Apache Tomcat服务器。我部署了该项目,这个数据表选择监听器没有问题。但是该项目已经部署了一周,之后我在数据表行选择监听器中得到NullPointerException
。当我重新启动Tomcat时,问题就解决了。每隔7天,8天发生此问题,并重新启动Tomcat解决此问题。
数据表是惰性的,有Person和Applications类。每个人都有很多申请。
下面是app.xhtml的一部分
<p:dataTable id="appDataTable"
var="applications"
value="#{appView.applicationLazy}"
rowKey="#{applications.id}"
paginator="true" rows="20"
emptyMessage="#{"No Record"}"
currentPageReportTemplate=" #{"Page"} ({currentPage}/{totalPages})"
paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink}
{RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100"
lazy="true"
selection="#{appView.selectedApplication}" selectionMode="single">
<p:ajax event="rowSelect"
onstart="ustPanel.collapse();"
update="detailPanel"
listener="#{appView.datatableRowSelectListener()}"/>
<p:ajax event="rowUnselect" update="detailPanel"/>
<f:facet name="header">
#{"Applications"}
</f:facet>
<p:column headerText="#{"name"}"
sortBy="#{appView.person.name}"
filterBy="#{appView.person.name}" >
<h:outputText value="#{appView.person.name}" >
</h:outputText>
</p:column>
<p:column headerText="#{"surname"}"
sortBy="#{appView.person.surname}"
filterBy="#{appView.person.surname}" >
<h:outputText value="#{appView.person.surname}" />
</p:column>
<p:column headerText="#{"mobilePhone"}"
sortBy="#{appView.person.mobilePhone}"
filterBy="#{appView.person.mobilePhone}"
>
<h:outputText value="#{appView.person.mobilePhone}" />
</p:column>
<p:column headerText="#{"date"}"
sortBy="#{appView.date}"
filterBy="#{appView.date}" >
<h:outputText value="#{appView.showDate(applications.date)}" />
</p:column>
<f:facet name="footer">
#{"total records"}: #{appView.applicationLazy.rowCount}
</f:facet>
</p:dataTable>
此处也是AppView bean类的一部分;
@ManagedBean
@ViewScoped
public class AppView extends BaseView implements Serializable {
private Applications selectedApplication;
private String name;
private String surname;
private String mobile;
private String date;
@PostConstruct
public void init() {
applicationLazy = new LazyDataModel<Basvurular>() {
@Override
public List<Applications> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) {
applicationLazy.setRowCount(commonService.applicationsProjection(filters));
return commonService.applicationsLazyLoad(first, pageSize, sortField, sortOrder, filters);
}
};
}
public void datatableRowSelectListener() {
try {
Locale loc = new Locale("tr", "TR");
date = selectedApplication.getDate();
name = selectedApplication.getPerson().getName().toUpperCase(loc);
surname = selectedApplication.getPerson().getSurname().toUpperCase(loc);
mobile = selectedApplication.getPerson().getMobilePhone();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
这是Tomcat的例外:
java.lang.NullPointerException
javax.el.ELException: /app.xhtml @55,173 listener="#{appView.datatableRowSelectListener()}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at
org.primefaces.component.behavior.ajax.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxBehaviorListenerImpl.java:53)
at
org.primefaces.event.SelectEvent.processListener(SelectEvent.java:40)
at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:102)
at
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
at javax.faces.component.UIData.broadcast(UIData.java:893)
at
javax.faces.component.UIData.broadcast(UIData.java:915)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:787)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1252)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute
(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute
(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:508)
at