Avoiding null point exception in el in JSF

Posted by Buddhika Ariyaratne on Stack Overflow See other posts from Stack Overflow or by Buddhika Ariyaratne
Published on 2012-06-23T02:35:28Z Indexed on 2012/06/23 3:16 UTC
Read the original article Hit count: 301

Filed under:
|
|
|
|

I am developing a JSF application with JPA(EclipseLink 2.0) and Primefaces. I want to know is there any way to avoid null point exception when el calls a property of a null object. I have described the situation. I have Bill class. There may be no or more BillItem objects with a Bill objects. Each BillItem object have Objects like Make, Country, Manufacturer, etc objects. I am displaying several properties of a bill within a single JSF file like this.

"#{billControlled.bill.billItem.modal.name}"

But if a bill is not selected, or when there are no bill items for a selected bill, the properties accessing in the el are null. I can avoid this by creating new objects for every bill, for example, new make for a new bill item, etc or by creating new properties in the controller itself for all the properties. But that is a very long way and feel like rudimentory.

Is there any good practice to avoid this null point exception in el in JSF?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsf