Data loading with JSF
Hi
I have a link when I click on that link I am opening a popup in that popup I have displayed the text fromDatabase.
But when first time I click on link I am getting error asNullpointerException.
But second time when I click on link I am able to displaytext from Database in that popup.
The popup i.e JSP I am opening on link click contains code as,
<%
Beanbean=(Bean)session.getAttribute("bean name from faces-config");
Collection col= bean.getmethod().getB2bErrorTxnCollection();
%>
Very first time I am getting Nullpointer Exception i.e. Mybean is not loaded uptill that time.
But second time my bean gets loaded & I am able to display text.
Why this happening ?
Thanks
Sandip
# 1
What's happening? Well, a NullPointerException means that some object is not instantiated yet (object == null) ..
So in this case the bean or even the result of getMethod() might be null. Just do a nullcheck and instantiate the object where needed. You can do this using the new keyword.
For example:if (object == null) {
object = new Object();
}
This is basic Java knowledge, do you know?
# 3
Well, like I explained, just add a null check and instantiate the object if needed.
<%
Bean bean = (Bean) session.getAttribute("bean name from faces-config");
if (bean == null) {
bean = new Bean();
}
Collection col = bean.getmethod().getB2bErrorTxnCollection();
%>
# 6
Hi BalusC
I agree that getMethod() returns null
but only first time link click its returning null second time link click its not retuning null
Ok let me write my code here
A.jsp
<t:commandLink action="#{bean.viewerror}" onclick="window.open('B.faces',100,100)"
Bean.java
so my viewerror() method is,
public void viewerror() {
lot = (B2bLotCanonicalV) getErrorRecordsDataTable().getRowData();
Collection col=lot.getB2bErrorTxnCollection();
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session=(HttpSession)facesContext.getExternalContext().getSession(true);
}
}
and B.jsp i m writing as,
><%
Bean bean=(Bean)session.getAttribute("bean name from faces-config");
Collection mycol= bean.getB2bLotCanonical_V().getB2bErrorTxnCollection();
%>
Sandip