Dashboard > WebWork 1 > WebWork CookBook > The Three Uses Of The Property Tag
  WebWork 1 Log In View a printable version of the current page.  
  The Three Uses Of The Property Tag
Added by Anders Hovmöller, last edited by Anders Hovmöller on Nov 05, 2004  (view change)
Labels: 
(None)

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:

  1. fetching a value and printing it.
  2. putting a value on the top of the value stack within its body.
  3. 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". Note that webwork 1.4 introduces a new push tag that achieves this functionality too, for the sake of clarity.

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.

Here are some more examples of fun to be had:

<ww:property value="x/y">
will print getX().getY()

<ww:property />
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().

With this example:

<ww:property value="x/y">

where are the functions defined? when is the class instantiated?

is there any more detailed information available?

Posted by Anonymous at Jan 22, 2003 15:27 | Permalink

so How to display in ui tag that if only String object stored in a List, which would , then, be used in tag like
<code>
<ww:iterator value"aList"/>
...
</ww:iterator>
</code>

Posted by Anonymous at Jun 29, 2004 03:09 | Permalink

The example for the jsp tag 'include' suggests using the property tag as:

<ww:property value="people[0]">
<ww:include value="'beaninfo.jsp'"/>
</ww:property>

When I tried to use it in this way I got the exception:

"According to TLD, tag ww:property must be empty, but is not"

Posted by Stephen Smith at Sep 20, 2004 11:32 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators