Here is an example of a tag that gets the shopping cart data from the parent tag (which in turn gets it from the session) and then iterates while providing child tags with a shopping cart item (one for each iteration).
Basically, the interface defines getShoppingCartItem() and the displayer tag that is placed inside doesn't need to know where that data comes from. It just calls getShoppingCartItem() of the parent.
For example, for that tag, the corresponding displayer is this:
As you can see, this displayer has a subtotal field that uses a float (I know, it's bad) but to illustrate a point about formatting. I can supply it with numerFormat attribute since the base displayer takes care of that.
So a simplified version of a template would look like this:
<store:ShoppingCartItemListForShoppingCartRetriever>
...this part loops...
$<store:ShoppingCartItemDisplayer field="subtotal" numberFormat="#0.00"/> ... and other tags
...this part loops...
</store:ShoppingCartItemListForShoppingCartRetriever>
The same thing with markers (if statements) those iterate only once or don't iterate at all.
Here is a shopping cart example from the site I mentioned.
<store:ShoppingCartInSessionStatusMatcher matchStatus="NONEMPTY">
<%@ include file="/cart_nonempty.inc" %>
</store:ShoppingCartInSessionStatusMatcher>
<store:ShoppingCartInSessionStatusMatcher matchStatus="EMPTY">
<%@ include file="/cart_empty.inc" %>
</store:ShoppingCartInSessionStatusMatcher>
The includes are simply to make managing the whole thing easier. I could've put the stuff right between the tags. In any case, only one of them iterates since the conditions are mutually exclusive.
To make it about a forum, a good example might be:
<UserInSession matchStatus="true">
<a href="/profile/<UserDisplayer field="user_id"/>.page">My Profile
</UserInSession>
<UserInSession matchStatus="false">
Log in
</UserInSession>
That's simplified, but the idea is that if a user is logged in, then the tag UserInSession also acts as a UserProvider (so that the user displayer inside can get fiels like user id or user name or any other field).
And the same user displayer tag can be used on the member list page, only inside a tag like UserListRetriever, which would also implement UserProvider.
[originally posted on jforum.net by bcc]