Hi,
Why would you use a chain of command for this kind of thing? If all you
need to do is look up some object by a key then a regular service should
suffice, no?
public interface OrganizationBlockSource {
Block getOrganizationBlock(OrganizationType type);
}
You could then look up a page, say OrganizationTypeBlocks, through
ComponentSource, get its ComponentResources and finally retrieve the
block you need:
public class OrganizationBlockSourceImpl implements
OrganizationBlockSource {
private final ComponentSource componentSource;
public OrganizationBlockSourceImpl(ComponentSource componentSource) {
this.componentSource = componentSource;
}
Block getOrganizationBlock(OrganizationType type) {
return
componentSource.getPage("OrganizationTypeBlocks").getComponentResources().getBlock(type.name
+ "Block");
}
}
I haven't tested this at all, mind you, but it should work nonetheless.
-Filip
On 2008-07-22 00:17, Bill Holloway wrote:
One of my domain data types (organization) will be endowed with a type
label (an enum). Each different type will need to have, on the page
that views the organization, a block that is dependent on that type.
These blocks are large and quite complex, so I don't want to define
those blocks in the view page's template. I'd like to put them in
separate components and then have a chain of command look up the right
component based on the type of the organization, return it, and
display it.
Schematically, the view page for the organization might look like
Organization.tml:
<h1>Organization</h1>
...
${myDisplayBlock}
...
Organization.java:
public Block getMyDisplayBlock ()
{
Block b = null;
_orgBlockLookup.findBlock(b, _org.getType()); // Chain of command
that sticks the right value in b.
return b;
}
But I'm not sure how to set up that chain of command! Any thoughts out there?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]