struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Drew Davidson <d...@running-start.com>
Subject Re: PROPOSAL: Change in Nested and Indexed Property Names Syntax
Date Thu, 21 Sep 2000 18:29:41 GMT
"Craig R. McClanahan" wrote:

> 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.

The reason that I ask is that there exists a good way of doing this with the OGNL
package (which is public domain) that includes this kind of graph navigation, plus
a whole lot more.  It is pure Java, compatible with Java 1 and 2 and includes ways
of accessing not only navigation paths (i.e. address.city), but methods for
calling methods explicitly, calling static methods and manipulating lists
(projection & selection, index extraction, etc.).  My company is currently using
this to great effect in our product and I think it would make a valuable addition
to Struts.

I've attached the description HTML so that you can evaluate it.

- Drew
--
Drew Davidson
Senior Software Engineer
Running Start, Inc.
(520) 547-4307
(520) 547-4339 (fax)
drew@running-start.com
http://www.running-start.com


Mime
View raw message