• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is EL null friendly??????

 
Luis Torres
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in HFSJ 2nd Ed page 399 that EL is null friendly, so it handles unknown properties and prints nothing.
But also the JSP specs says:


Otherwise (a JavaBeans object), coerce value-b to String
f value-b is a readable property of value-a, as per the JavaBeans specification:
� If getter throws an exception: error
� Otherwise: return result of getter call
Otherwise: error.


So if EL don't find property it should throws a Exception

I try this:

1. ${requestScope.mybean.noProperty } ----- error
2. ${requestScope.mybean[noProperty ] } ----- prints nothing

According the specs number 2 also should throws error. Right?
and according the specs is EL null-friendly? Why?

Thanks
 
Vijay Bharghav bheemineni
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Luis,

The second option doesn't throw error. It will display blank. Below are notes from JSP spec.

To evaluate expr-a[expr-b]
Evaluate expr-a into value-a
If value-a is null then return null.
Evaluate expr-b into value-b
if �value-b� is null then return null.

Below answer's your second query.
Points from JSP 2.3.3

JSP pages are mostly used in presentation, and in that usage, experience suggests that it is most important to be able to provide as good a presentation as possible,even when there are simple errors in the page. To meet this requirement, the EL does not provide warnings, just default values and errors.

Thanks.

Vijay Bheemineni.
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luis,
1. ${requestScope.mybean.noProperty }

When you use dot, interpreter treats it as a property(in case of Bean), if it finds the property it returns appropriate value, if it doesn't find the property it throws an exception.
2. ${requestScope.mybean[noProperty ] }

In the case of [] you should be very careful, it treates it as an scope attribute, that is, it searches for an attribute 'noProperty' in all scopes. If you change your [] code as below, it works fine.
String cc = "noProperty";
session.setAttribute("noProperty",cc);
${requestScope.mybean[noProperty] }

(or)
${requestScope.mybean['noProperty'] }

(or)
${requestScope.mybean["noProperty"] }

There is lot to say, hope this is sufficient to serve your purpose.

Regards,
Ravi
[ May 30, 2008: Message edited by: Garla Ravi ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic