...
For example, suppose we are using standard OGNL (not using XWork) and there are two objects in the OgnlContext map: "foo" -> foo and "bar" -> bar and that the foo object is also configured to be the single root object. The following code illustrates how OGNL deals with these three situations:
Code Block |
---|
#foo.blah // returns foo.getBlah()
#bar.blah // returns bar.getBlah()
blah // returns foo.getBlah() because foo is the root
|
...
For example, suppose the stack contains two objects: Animal and Person. Both objects have a "name" property, Animal has a "species" property, and Person has a "salary" property. Animal is on the top of the stack, and Person is below it. The follow code fragments help you get an idea of what is going on here:
Code Block |
---|
species // call to animal.getSpecies()
salary // call to person.getSalary()
name // call to animal.getName() because animal is on the top
|
In the last example, there was a tie and so the animal's name was returned. Usually this is the desired effect, but sometimes you want the property of a lower-level object. To do this, XWork has added support for indexes on the ValueStack. All you have to do is:
Code Block |
---|
[0].name // call to animal.getName()
[1].name // call to person.getName()
|
...
OGNL's static access looks like this:
Code Block | ||||
---|---|---|---|---|
| ||||
@some.package.ClassName@FOO_PROPERTY
@some.package.ClassName@someMethod()
|
However, XWork allows you to avoid having to specify the full package name and call static properties and methods of your action classes using the "vs" prefix:
Code Block |
---|
<at:var at:name="vs" />FOO_PROPERTY
<at:var at:name="vs" />someMethod()
<at:var at:name="vs1" />FOO_PROPERTY
<at:var at:name="vs1" />someMethod()
<at:var at:name="vs2" />BAR_PROPERTY
<at:var at:name="vs2" />someOtherMethod()
|
...