• Post Reply Bookmark Topic Watch Topic
  • New Topic

Showing Date if no value  RSS feed

 
Joseph Smithern
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Date variable in a JavaBean that works with a Oracle Database.
If there is a Date value in the database it shows in the JSP with no problems.
But if there is no value in the Date value it gives me a null error in the JSP.
How do I account for null with a Date object?

If there is not Date value I still want the page to show the Date Title with nothing there.
For example:
JSP view example if there is a Date value:
Submit Date: June 25, 2007

JSP view example if there is not a Date value should show like this but it doesnt show and gives me a null error:
Submit Date:


My classes and JSP:

Bean:


Helper class:


JSP Bean call

[ April 21, 2008: Message edited by: Joseph Smithern ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I moved this from the JSP forum since the issue is with basic Java rather than JSP.

Look at your code again:

What is the purpose of your "if" clause? If the value is null, you set it to null, which is the value it already was. What were you trying to accomplish? And then you go right on ahead passing it to the format() method, which of course, still gives you a null pointer exception.

Try to think of how you might use the null check to do something other than passing null to the format routine. How could you still return something useful from the method?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That method won't compile either. You declare to return a Date object, but in fact you return a String.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!