I came across the same problem so i changed the component implementation.
Here's the changed component.
Hope this helps.
Cheers
Hugo
phillip rhodes wrote:
I am using a cool little component someone wrote
called DynamicBlock.
Unfortunately, I just figured out that DynamicBlock
appears to be limited to finding and rendering
components within the same library that it is declared
in.
It subclasses the BaseComponent and uses the
getComponents() method to search for the named block
that you want to render. My block is defined in
another library, so the component is never found.
Has anyone ever tried to located from one library a
reference to a component within another library?
Is there a way to obtain a list of all components in a
particular namespace?
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
package pt.digitalis.dif.view.components.dynamic;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.tapestry.BaseComponent;
import org.apache.tapestry.IComponent;
import org.apache.tapestry.IRender;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.components.Block;
import org.apache.tapestry.engine.IPageLoader;
import org.apache.tapestry.spec.IComponentSpecification;
/**
* Class for DynamicBlock component.
*
* @author Michael Anderson
*/
public abstract class DynamicBlock extends BaseComponent
{
private Block _block;
public abstract String getComponentName();
public abstract void setComponentName(String s);
public abstract IPageLoader getPageLoader();
public Block getBlock()
{
return _block;
}
public void finishLoad(IRequestCycle cycle, IPageLoader loader,
IComponentSpecification specification)
{
_block = findBlockForComponentNamed(getComponentName());
super.finishLoad(cycle, loader, specification);
}
private Block findBlockForComponentNamed(String name)
{
String blockId = name + "Block";
Block block = lookupBlock(blockId, name);
if (block == null) block = constructBlock(blockId, name);
return block;
}
private Block lookupBlock(String blockId, String bodyComponentName)
{
boolean shouldThrow = false;
Block block = null;
IComponent component = null;
try
{
block = (Block) getComponent(blockId);
if (block == null) return null;
if (getBodyCount() > 0)
{
component =
block.getComponent(bodyComponentName);
shouldThrow =
!component.getSpecification().getAllowBody();
}
}
catch (Exception exception)
{
}
if (shouldThrow) throw new
ApplicationRuntimeException("DynamicBlock has a body, but component: " +
component.getId() + " does not allow a body", getLocation(), null);
else return block;
}
private Block constructBlock(String id, String bodyComponentName)
{
IRequestCycle cycle = getPage().getRequestCycle();
Location location = getLocation();
Block block = (Block)
getPageLoader().createImplicitComponent(cycle, getContainer(), id, "Block",
location);
IComponent component =
getPageLoader().createImplicitComponent(cycle, getPage(), bodyComponentName,
bodyComponentName, location);
block.addBody(component);
int bodyCount = getBodyCount();
if (bodyCount > 0)
{
boolean allowsBody =
component.getSpecification().getAllowBody();
if (allowsBody)
{
IRender bodyElements[] = getBody();
for (int i = 0; i < bodyCount; i++)
component.addBody(bodyElements[i]);
}
else
{
throw new
ApplicationRuntimeException("DynamicBlock has a body, but component: " +
component.getId() + " does not allow a body", location, null);
}
}
return block;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]