• Post Reply Bookmark Topic Watch Topic
  • New Topic

Expression Language, Tomcat and JasperException  RSS feed

 
Piotr Kiraga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I'm wondering for couple of days how to resolve one problem in my JSP.
I don't know how to configure Tomcat to pass through:
${someBean.someField}
without exception, even if someField doesn't exist in someBean class.

Is it possible?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not possible as that would be a violation of the JSP Specification. If the property does not exist on the bean, an exception will be raised.
 
Piotr Kiraga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've assumed like You. But some time ago I've received such a post:

I don't know why ${!empty actionBean.result} would throw that exception. When I do that in my JSP, it just prints "false", even if my action bean doesn't have a result property, but I'm using Resin.
...cut...
If it's throwing an exception, I think that is a tomcat problem.


So, You suggest, that it's not true and this exception in my Tomcat is appropriate?

Some background:
I'm trying to use one JSP file for two classes/actions in Stripes MVC framework. When it's requested from first action there doesn't exist some property in other case it exists. In Struts it's easy to check by struts taglibs. Here (in Stripes) I have a little problem.
[ February 20, 2007: Message edited by: Piotr Kiraga ]
 
Piotr Kiraga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
It is not possible as that would be a violation of the JSP Specification. If the property does not exist on the bean, an exception will be raised.


Otherwise. How to check safely (by EL) that bean exists, and furthermore, that it has a property.

Regards.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The relevant language from the JSP Specification, while terse, is crystal clear:

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.


So, no.

And that's to be expected. Bean properties are not dynamic. Each bean has its properties and they should be well-known and they do not change over the life of the bean.

For a construct with dynamic properties, you might want to investigate using a Map. This article discusses just that.
[ February 22, 2007: Message edited by: Bear Bibeault ]
 
Piotr Kiraga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for Your reply.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!