Saturday, 31 August 2013

Null Pointer Exception when method is invoked too many times

Null Pointer Exception when method is invoked too many times

I have a page where I set date and specialization:
<form>
<p:panel header="Szukaj wizyty">
<p:panelGrid columns="2">
<p:outputLabel for="Od"
value="Od"></p:outputLabel>
<p:calendar id="Od" label="Od"
value="#{visitPatientMB2.start}" effect="fold"
locale="pl" pattern="dd/MM/yyyy"
mindate="#{visitPatientMB2.actualDate}"
required="true">
<p:ajax event="dateSelect"
listener="#{visitMB.enableCalendar()}"
update="cal" />
</p:calendar>
<p:outputLabel for="Do"
value="Do"></p:outputLabel>
<p:calendar id="Do" label="Do"
value="#{visitPatientMB2.end}" effect="fold"
locale="pl" pattern="dd/MM/yyyy"
disabled="#{visitMB.flag}"
mindate="#{visitPatientMB2.actualDate}"
required="true"/>
<p:outputLabel
value="Specjalizacja"></p:outputLabel>
<p:selectOneMenu id="specialization"
value="#{visitPatientMB2.user.specializationId}"
effect="fade" style="width:200px"
converter="#{specializationConverter}">
<f:selectItems
value="#{visitPatientMB2.allSpecialization}"
var="specialization"
itemValue="#{specialization}"
itemLabel="#{specialization.name}"/>
</p:selectOneMenu>
<center><p:commandButton
action="#{visitPatientMB2.searchStart()}"
value="Szukaj" /></center>
</p:panelGrid>
</p:panel>
</form>
this page causes method: visitPatientMB2.searchStart()
VisitPatientMB2 RequestBean:
@ManagedBean
@RequestScoped
public class VisitPatientMB2 {
@EJB
private VisitDaoLocal visitDao;
@EJB
private SpecializationDaoLocal specializationDao;
@EJB
private UserDaoLocal userDao;
private Specialization specialization;
private Visit visit;
private User user;
private Date actualDate = new Date();
private Date start;
private Date end;
private boolean flag = true;
private Integer myId;
public VisitPatientMB2() {
}
public void enableCalendar() {
if (start != null) {
flag = false;
}
}
public String searchStart() {
System.out.println("SEARCH START");
if (start.after(end)) {
sendErrorMessageToUser("Data zakoñczenie nie mo¿e byæ
wczeœniejsza ni¿ rozpoczêcia");
return null;
}
if (start.before(actualDate)) {
sendErrorMessageToUser("Data wizyty nie mo¿e byæ wczeœniejsza
ni¿ aktualna data");
return null;
}
return "searchStart";
}
public String visitRegister() {
System.out.println("visitRegister");
myId = (Integer) session.getAttribute("myId");
visit.setPatientId(userDao.find(myId));
try {
visitDao.update(visit);
sendInfoMessageToUser("Wizyta zosta³a dodana");
return "addVisit";
} catch (EJBException e) {
sendErrorMessageToUser("B³¹d zapisu na wizyte do bazy");
return null;
}
}
public List<Visit> getVisitFound() {
System.out.println("start" + start);
System.out.println("end" + end);
System.out.println("name" + user.getSpecializationId().getName());
myId = (Integer) session.getAttribute("myId");
return visitDao.visitSearch(start, end,
user.getSpecializationId().getName(), myId);
}
public List<Specialization> getAllSpecialization() {
return specializationDao.findAllSpecialization();
}
Method return searchStart and go to page searchResult, no redirect
<navigation-rule>
<from-view-id>/protected/patient/visitSearch.xhtml</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/protected/patient/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>about</from-outcome>
<to-view-id>/protected/patient/about.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>gallery</from-outcome>
<to-view-id>/protected/patient/gallery.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>contact</from-outcome>
<to-view-id>/protected/patient/contact.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>myAccount</from-outcome>
<to-view-id>/protected/patient/patientPanel.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitList</from-outcome>
<to-view-id>/protected/patient/myVisits.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitRegister</from-outcome>
<to-view-id>/protected/patient/visitRegister.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitSearch</from-outcome>
<to-view-id>/protected/patient/visitSearch.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>history</from-outcome>
<to-view-id>/protected/patient/myHistory.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>editMyAccount</from-outcome>
<to-view-id>/protected/patient/myAccount.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>searchStart</from-outcome>
<to-view-id>/protected/patient/searchResult.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addVisit</from-outcome>
<to-view-id>/protected/patient/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
and when I in the page searchResult i click save to visit and run the
method visitPatientMB2.visitRegister() but I have a error...
WARNING: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException
javax.el.ELException: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at
org.primefaces.component.datatable.DataTable.getValue(DataTable.java:867)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:579)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:409)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.api.UIData.processPhase(UIData.java:258)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:227)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:933)
at
com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
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:593)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at pl.ePrzychodnia.filter.FilterLogin.doFilter(FilterLogin.java:49)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at
pl.ePrzychodnia.mb.VisitPatientMB2.getVisitFound(VisitPatientMB2.java:215)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
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.AstValue.getValue(AstValue.java:138)
at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 46 more
Why i have null? I not redirect page, my bean is a request, why filed is
null?
I set in the method:
public List<Visit> getVisitFound() {
System.out.println("start" + start);
System.out.println("end" + end);
System.out.println("name" + user.getSpecializationId().getName());
myId = (Integer) session.getAttribute("myId");
return visitDao.visitSearch(start, end,
user.getSpecializationId().getName(), myId);
}
and I see, when i go the page search result. This method is invoked twice.
Why?
And when I run visitPatientMB2.visitRegister() in page searchResult method
starts the third time... This time fields have null. Example:
INFO: startSun Sep 01 00:00:00 CEST 2013
INFO: endSun Sep 29 00:00:00 CEST 2013
INFO: nameKardiolog
INFO: startSun Sep 01 00:00:00 CEST 2013
INFO: endSun Sep 29 00:00:00 CEST 2013
INFO: nameKardiolog
INFO: startnull
INFO: endnull
WARNING: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException

No comments:

Post a Comment