You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Borislav Iordanov <bo...@kobrix.com> on 2003/02/07 02:10:48 UTC
tag attributes as bean properties
Hi guys,
This is more a question for tomcat developers I guess. I'm working with
Tomcat 4.1.18.
The JSP 1.2 specification states that a container should interpret tag
attributes as bean properties following the Java Beans specification.
Does Tomcat then rely on a BeanInfo associated with a bean to find out
about property setters and getters? It doesn't seem so since I defined a
BeanInfo class for a tag handler class and the
'BeanInfo.getPropertyDescriptors' never gets called.
My goal is the following: I would like to allow a tag attribute which is
semantically a boolean to be set either through
(1) a string ("true" or "false") or
(2) a run-time expression (e.g. '<%= bar.getFoo() != null %>') or
(3) an EL expression (e.g. "${not empty bla.foo}")
The problem is that the EL expression gets converted at translation time
to a false boolean. Therefore, I would like to bypass the standard
String->primitive_type conversions performed by the JSP translator.
Thanks a lot in advance,
Boris
____________________________________________
Borislav Iordanov
Chief Architect
TICL - a RAD toolkit for server-side Java
http://www.kobrix.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: tag attributes as bean properties
Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Borislav" == Borislav Iordanov <bo...@kobrix.com> writes:
Borislav> Hi guys,
Borislav> This is more a question for tomcat developers I guess. I'm working with
Borislav> Tomcat 4.1.18.
Borislav> The JSP 1.2 specification states that a container should interpret tag
Borislav> attributes as bean properties following the Java Beans specification.
Borislav> Does Tomcat then rely on a BeanInfo associated with a bean to find out
Borislav> about property setters and getters? It doesn't seem so since I defined a
Borislav> BeanInfo class for a tag handler class and the
Borislav> 'BeanInfo.getPropertyDescriptors' never gets called.
Borislav> My goal is the following: I would like to allow a tag attribute which is
Borislav> semantically a boolean to be set either through
Borislav> (1) a string ("true" or "false") or
Borislav> (2) a run-time expression (e.g. '<%= bar.getFoo() != null %>') or
Borislav> (3) an EL expression (e.g. "${not empty bla.foo}")
Borislav> The problem is that the EL expression gets converted at translation time
Borislav> to a false boolean. Therefore, I would like to bypass the standard
String-> primitive_type conversions performed by the JSP translator.
I don't read this list very often, so I don't know if you still need this
information.
I've had this exact problem. I had a base class tag with attributes of certain
types (not string), and I defined a subclass tag whose attribute values are
evaluated with the EL.
For instance, assume your attribute is named "foo", as defined in your TLD. In
the base class, this is a boolean instance variable.
Along with my subclass, I have a BeanInfo class which maps the "foo" attribute
to a setter "setFooExpr()". I have an instance variable named "fooExpr" in my
subclass, along with getter/setter "getFooExpr()" and "setFooExpr()".
In my "doStartTag()" method, I pass the value of "getFooExpr()" into the EL
evaluator and send the result to "setFoo()".
This will definitely deal with your cases "(1)" and "(3)", and I believe it
will handle "(2)", but I haven't tried that (I avoid scriptlets).
If you want to see numerous examples of this, I implemented this in the
Struts-EL contributed package in the Struts distribution.
--
===================================================================
David M. Karr ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net ; SCJP; SCWCD
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org