Avoiding null point exception in el in JSF
- by Buddhika Ariyaratne
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?