This document assumes you understand the concept of the value stack and have some knowledge of the WebWork expression language.The <webwork:property> tag has THREE distinct use cases:
- fetching a value and printing it.
- putting a value on the top of the value stack within its body.
- putting a value into the page context.
If the body of the tag is empty, for example
<webwork:property value="foo"/>
or
<webwork:property value="foo"></webwork:property value="foo">
, it will automatically use the first use case, i.e. print the value.If the body is not empty,
<webwork:property value="foo">foo</webwork:property value="foo">
, it will use the second use case. Observe that even one space or newline is counted as "not empty".By default, it will escape HTML characters for use case 1. Tags with bodies will not be
escaped by default. You can override this with explicit setting of the escape attribute.
Quoted text that is escaped will have its outer quotes stripped.If id is specified, it will use the third use case.
<webwork:property id="foo" value="bar" />
will grab the value "bar" from the value stack and put it into the page context as "foo". It will be added both to the page scope and to the request scope. Note that webwork 1.4 introduces a new push tag that achieves this functionality too, for the sake of clarity.Here are some more examples of fun to be had:<ww:property value="x/y">
will print getX().getY() will print what's on the top of the stack. This is very useful to debug where you are on the stack - and often will print out the toString() method of your action.
So why is the second use case useful?
It makes your code simpler and easier to read!<ww:property value="someUser">
<ww:property value="name" />
<ww:property value="fullName" />
<ww:property value="email" />
</ww:property>
This will print out the attributes (getName, getFullName(), getEmail()) of the user object obtained from getSomeUser().The alternative is much more difficult to read, and potentially slower:<ww:property value="someUser/name" />
<ww:property value="someUser/fullName" />
<ww:property value="someUser/email" />
Potentially slower? Yes - because the first code snippet only calls getSomeUser() once - whereas the second makes 3 calls to getSomeUser() - so your user lookup might be done 3 times.You can also use the .. operator to refer back to other things if you wanted to like so:<ww:property value="someUser">
<ww:property value="name" />
<ww:property value="../score(.)" />
</ww:property>
The "../score(.)" will call yourAction.getScore(someUser) where someUser is the object obtained from getSomeUser().