• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best practices for avoiding DisplayTag:Table NullPointers

 
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm faced with a nullpointer issue on one of my JSP pages, I have some ideas of how to avoid this but I'd like some advice on some better ways.

I have the following on my page, this page displays only one of my "prospect" objects, depending on which one I clicked on the previous page :



This works fine for my "prospect" objects that have values in their "contacts" lists

I'm getting the null pointer if I access this JSP page for a "prospect" that doesn't have anything set for "contacts". This may well be the case if I were to create a new prospect, after just being created it would have no notion of contacts, unless I were to initialise a blank item in the list of contacts, but that seems rather a stupid way of patching this problem.

I've had a look at the display tag documentation, I can't see any way to display "no data found" on the table if the set of data is null

Any suggestions on how I could best tackle this?
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been having a play with this over the weekend and it seems that the display:table will return an error if my ArrayList is of size 0

For example, I get the following error



Now, this is what I use to generate some dummy data that I want to display...





prospect1 shows up on my JSP fine, it shows all the "prospect" attribute, then the 2 contacts. No worries there. I get the error when I go to the prospect 2 page. I was hoping that by calling .setContacts on prospect2 and passing in an empty array list I'd be fine, but that doesn't seem the case.

What can I do? There may be cases where there are no "contacts" at all, I don't really want to have to set a default dummy contact just to get around this

Any ideas?

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic