Geoff,

I know this - please feel free to write up a short doc and we'll include it
in the docs =P

But for asking, here's some more funkiness that you can do:

Assume you have two objects like Foo and Bar, both of which have a getName()
and getId() method (they might have a common interface, they might be
_totally_ different).

Now assume you have an action with some method signatures like this:

public String[] getAllFoos()
public List getAllBars()

You can now write a generic 'display list' include, using a bit of property
tag magic.

<webwork:property value="allFoos">
   <%@ include file="genericlist.jsp" %>
</webwork:property>

<webwork:property value="allBars">
   <%@ include file="genericlist.jsp" %>
</webwork:property>

What? But they're totally different objects and one is an array while the
other is a list? - answer: who cares? :)

The include file could look like so:

<webwork:iterator> 
   <a href="viewitem.action?id=<webwork:propertyvalue="id"
/>"><webwork:property value="name"></a><br>
</webwork:iterator>

How cool is that?

The iterator tag uses no value, which is the equivalent of value="." - or
the top object on the stack (here our String[] or List).

This sort of trickery can save you lots of code, especially with many
different value objects that are kind of similar. And because webwork is so
forgiving, they don't even need to be _exactly_ similar.

To spin your mind more - we could have a list of _mixed_ Foo and Bar objects
- and the above would print them _all_ out perfectly.

What if we had a Baz object that has no getId() method, but just a
getName(). With a simple if clause, we could then print those as well - like
so:

<webwork:iterator> 
   <webwork:if test="id">
      <a href="viewitem.action?id=<webwork:propertyvalue="id"
/>"><webwork:property value="name"></a>
   </webwork:if>
   <webwork:else>
      <webwork:property value="name">
   </webwork:else>
</webwork:iterator>

This will now print any 'iteratable' object (array, list, collection, XML
node list, vector, enumeration iterator etc) containing any objects with a
getName() method (and note that those getName() methods could return String
or any Object that is printable!)


Make sense? Maybe not - let me know if it isn't clear - read it a few times.
Trust me that it is cool ;)

-mike





On 2/11/02 5:59 AM, "Geoff Carruthers" ([EMAIL PROTECTED])
penned the words:

> You wrote:
>> 
>> For the dummies:
>> 
>> <ww:property> has TWO uses:
>> 
>> 1: <ww:property value=3D"x" /> will grab the value of x and print it
>> 2: <ww:property value=3D"x"> ... </ww:property> will grab the value of =
> x and
>> make it 'available' between the tags.
>> 
>> That's it!
>> 
>> Some more examples of fun to be had (from my 'teach ww to the coworkers=
> '
>> spiel)
>> 
>> <ww:property value=3D"x/y"> will print getX().getY()
>> 
>> <ww:property /> will print what's on the top of the stack (very useful =
> to
>> debug where you are!
>> 
>> Why is #2 above useful? It makes your code simpler and easier to read!
>> 
>> <ww:property value=3D"someUser">
>>    <ww:property value=3D"name" />
>>    <ww:property value=3D"fullName" />
>>    <ww:property value=3D"email" />
>> </ww:property>
>> 
> 
> As a dummy, I really appreciate this description of what the property tag
> does.  It's clear, concise, complete, and useful.  The only problem is its
> location: not in the documentation where all us dummies can easily find it,
> but on the mailing list where most of the participants already know how it
> all works.
> 
> Let me remind you what the "official" documentation says about the property
> tag:
> 
>> property tag
>> 
>> Used to retrieve a value and print it out. By default, it will escape HTML
> characters for tags with *no* bodies. Tags with >bodies will not be escaped.
> You can override this with explicit setting of the escape attribute. Quoted
> text that is >escaped will have its outer quotes stripped.
>> 
>> Attributes
>> 
>> 
>> attribute requied
>> id F
>> value F
>> escape F
>> 
>> In this example, property will call getTime() on the object pointed to by
> @timer.
>> 
>> 
>> Time:<webwork:property value="@timer/time"/>ms
> 
> You guys have a great product in WebWork, but it is *incredibly* frustrating
> trying to find answers about how to use it in the skimpy documentation.  For
> all the ink you spill over issues like this and null tests vs. boolean
> tests, you would think some of it could find it's way into the docs where
> everybody would be enlightened.
> 
> Just a plea from a humble dummy.  I know I'm not the only one.
> 
> Geoff
> 
> 
> 
> 
> 
> -------------------------------------------------------
> This sf.net email is sponsored by: See the NEW Palm
> Tungsten T handheld. Power & Color in a compact size!
> http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
> _______________________________________________
> Opensymphony-webwork mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork



-------------------------------------------------------
This sf.net email is sponsored by: See the NEW Palm 
Tungsten T handheld. Power & Color in a compact size!
http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork

Reply via email to