Foros de discusión

null check for object

thumbnail
Shilpa B, modificado hace 11 años.

null check for object

Junior Member Mensajes: 61 Fecha de incorporación: 2/08/12 Mensajes recientes
As I'm fetching data from web services and displaying in my portlet. Around 5 filed are there, in that sometimes some of fields may be null. because of this filed whole portlet not getting displayed.

As i have to check for null, and I'm doing in this way. Is this the correct approach for null check?

String reqLastRD = fetching form web service;
if (reqLastRD != null)
{
reqLastRD = fetching form web service;
} else
{
reqLastRD = "";
}
renderRequest.setAttribute("reqLastRD", reqLastRD);

please suggest me the right approach for null check.

thank you in advance...
thumbnail
Nagendra Kumar Busam, modificado hace 11 años.

RE: null check for object

Liferay Master Mensajes: 678 Fecha de incorporación: 7/07/09 Mensajes recientes
Try Validator.isNull(String s)
thumbnail
Amit Doshi, modificado hace 11 años.

RE: null check for object

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Shilpa B:
As I'm fetching data from web services and displaying in my portlet. Around 5 filed are there, in that sometimes some of fields may be null. because of this filed whole portlet not getting displayed.

As i have to check for null, and I'm doing in this way. Is this the correct approach for null check?

String reqLastRD = fetching form web service;
if (reqLastRD != null)
{
reqLastRD = fetching form web service;
} else
{
reqLastRD = "";
}
renderRequest.setAttribute("reqLastRD", reqLastRD);

please suggest me the right approach for null check.

thank you in advance...


Try using Validator.isNotNull function from the Validator Class.