Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF pg- 447- Key Points with c:set

 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The last key point about <c:set> says that the statement :

${fooBean.notAProperty} wont cause an exception by itself (It will return null)

I am not sure if that is correct.

If "fooBean" does not have a property with name "notAProperty" then it will throw ELException.

If fooBean does not exist in any of the scope (page,request,session , application) , then it will return null.

Please let me know if I am wrong?

Regards

Prem Kashyap
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you do this : ${foo.omi} then it will return null not exception.

c:set comes in two flavor as you know the thing which throws exception is
c:set target not c:set var.

c:set target wants object as a values.

you need to write one or two program to get more clear picture.

best regards,
omi
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are right, when you say:
If "fooBean" does not have a property with name "notAProperty" then it will throw ELException.

JSP spec. 2.3.4
...

Otherwise (a JavaBeans object), coerce value-b to String
If 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.]
 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John,
I have confirmed by running a small program and if we try to access bean property which does not exist, it throws an exception.

Omi : The exception will be caused if you are tying to access a property of a bean that does not exist.

So if "foo" is a bean which is stored in request scope.
If you give ${foo.omi), where there is no getter for omi (as there is no propery named omi in the foo bean), then it will cause exception. Irrespective of whether you give it in c:set var or c:set target of any other JSP tags..

In case the "foo" bean does not exist as attribute in any of the scope,

and you give ${foo.omi}, this will return null (displayed as blank in JSP page), as foo itself was not found, so there was no attempt to get property omi

Regards

Prem Kashyap
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Man , you might have noticed I did not try to solve your question but
rather was asking another question.

by the way ,you have raised very valuable point.

thanks for the solution.

best regards,
omi
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic