Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

El expression in JSF

 
Bushra Binte
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,How to validate null pointer exception in EL expression.Here is what m trying to do.I am using ui:textField tag and in text attribute isthis value

text="#{sessionScope.orderInfo.hStuff != null ? sessionScope.orderInfo.hStuff : ""}".I am gettting an error saying
"ui:textField must be followed by either atribute specifications,">" or "/>".Please help
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your actual problem is that you should use singlequotes instead of doublequotes inside the EL expression.

But actually you don't need to do nullchecks in EL. Just write out the full expression. EL won't display the value as "null" or so, just an empty string.
 
Bushra Binte
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,idid that as 'null' was displayed in the textfield.Now i changed to sinquotes,i get this error msg displyed at the top of the screen:
"com.sun.faces.el.impl.ElException: Read-only expressions can't be set"
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, that property holds a String value of "null" instead of the literal null?
 
Bushra Binte
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am afraid its not..
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haven't seen that before.

What JSF implementation/version and which component library are you using? What application server implementation/version are you using?

Here's a small testcase which should just work on Mojarra 1.2_12 / Tomcat 6.0.18:




In none of the both cases a "null" is displayed. Just an empty string. Exactly as stated in the EL specification.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18167
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A lot of times, a database will end up with the actual text word "null" in a column after a binding mechanism has been used to edit the table row. That happens when the display mechanism pushed the word "null" out to the user form and the user then sent it back.

There's a big difference between no value (null) and and empty string (""). Unfortunately, text editing displays usually don't handle that, and people aren't very good at it either. It's best to avoid using null in databases except in cases where null means literally "no data available". Even then, you should be prepared to handle the distinction.

The problem can be even worse for numeric fields than it is for text fields. I've dealt with systems that had major complications because the data store was designed with null numeric fields.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic