Drew Davidson wrote:
>
> Sorry, but I don't really keep up with this list very much - is there an
> ECMAScript interpreter on the server that is executing these statements
> (like address.city -> getAddress().getCity())?
>
No, it doesn't quite work like that.
Struts includes a PropertyUtils.getProperty() method that takes an object (the
bean) and the "name" of a property to be retrieved, and returns an Object that
is the value of that property. It uses the Java reflection APIs to figure out
how to do this. In Struts, this is used (for example) when populating the
properties of a form bean, or in the form tags when they look up the current
values of bean properties.
For simple property names like "address", the reflection APIs know how to tell
me to call getAddress(), so that's easy. For the nested syntax
("address.city" the old way, "address_city" the proposed new way), the
getProperty() method scans the "name" parameter and splits it up.
Effectively, we do a getAddress() call, and then a getCity() call, parsing our
way down whatever "name" the calling program specified.
The issue for JavaScript is that the Struts form tags use the property name
you specify as the name of the corresponding input field (and therefore the
corresponding request parameter you get back). For non-Javascript use, that
is no big deal -- you end up with something like this (using the old syntax):
<input type="text" name="address.city" value="Los Angeles">
which works fine. The problem we're trying to solve is, what happens if you
want to reference this text field with JavaScript? The "." delimiter is
significant, so you can't just say:
forms["formname"].address.city = "San Francisco"
and have it do the right thing.
Someone else responded that you might be able to work around this (in
JavaScript) using "id" attributes instead of "name". I have not had a chance
to look into this yet.
>
> - Drew
Craig
====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00): Sun Technical Briefing
Session T06 (24-Oct 14h00-15h00): Migrating Apache JServ
Applications to Tomcat
|