• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getters show null sometimes

 
Smoke Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have two jsp files that use the getter of a CMP bean to display information. The first page is a list of items and I use the bean getter to display the information in a table <td><%=salaryPlan.getSalary()%><td>

If the value is null in the database nothing is returned and the output looks like <td></td>

Then on an update page I use the getter to put the info into a form and text fields. <td><input type="text" name="salary" value = "<%=salaryPlan.getSalary()%>"><td>

And in this case a null value is returned as "null"

The first uses <EJB:useBean> and the second uses <EJB:iterate>. This seems to be what is causing the problem. Don't know why.

How can I make the useBean tag output nothing when a null value is present?

Thanks for your time.

Smoke
[ August 05, 2004: Message edited by: Smoke Williams ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not the useBean tag's job to modify any data.

You should either ensure that the bean will never return a null value, or you can handle it on the page as follows:



assuming that the salary property is a String.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. If salary is not a String, then the more verbose



should do the trick.

Personally I prefer to keep the pages simple and make sure the the data and/or beans sent to the page are "page-friendly".
[ August 05, 2004: Message edited by: Bear Bibeault ]
 
Smoke Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response. I know that I could check each getter for a null value and then supply something else, but I am wondering why <EJB:iterate> and <EJB:useBean> give different results. Using iterate doesn't actually print "null" into the html while useBean does.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but I am wondering why <EJB:iterate> and <EJB:useBean> give different results


Not being familiar with the EJB tag set, I couldn't say. It could be as simple as one checks for null and substitutes the emptry string, and the other does not.

In any case, if a scriplet expression ever evaluates to null, it will emit the string "null".
 
Smoke Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear.

The EJB lib comes with Oracle JDeveloper. Just wanted a quick and easy way to solve the null problem. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!