wood burning stoves 2.0*
The moose likes JSF and the fly likes El expression in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "El expression in JSF" Watch "El expression in JSF" New topic
Author

El expression in JSF

Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
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

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Nov 07, 2006
Posts: 60
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

Joined: Oct 08, 2006
Posts: 2458
So, that property holds a String value of "null" instead of the literal null?
Bushra Binte
Ranch Hand

Joined: Nov 07, 2006
Posts: 60
i am afraid its not..
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: El expression in JSF
 
Similar Threads
jasper reports with subreports
pass <bean:write> to a function
how to implement dynamic rows paging when user clicks next or previous links
iterate problem in struts2
Combo box hiding when using jQuery form transformation