org.apache.tapestry.components
Class BlockRenderer

java.lang.Object
  extended by org.apache.tapestry.components.BlockRenderer
All Implemented Interfaces:
IRender

public class BlockRenderer
extends Object
implements IRender

An implementation of IRender that renders a Block component.

The BlockRenderer allows the contents of a Block to be rendered via IRender. It can be used in cases when an IRender object is required as an argument or a binding to render a part of a Component. To provide a complicated view, it could be defined in a Block and then returned encapsulated in a BlockRenderer.

It is important to note that a special care has to be taken if the BlockRenderer is used within an inner class of a component or a page. In such a case the instance of the component that created the inner class may not be the currently active instance in the RequestCycle when the BlockRenderer is required. Thus, calling getComponent("blockName") to get the block component may return a Block component that is not initialized for this RequestCycle.

To avoid similar problems, the ComponentAddress class could be used in conjunction with BlockRenderer. Here is a quick example of how BlockRenderer could be used with ComponentAddress:


// Create a component address for the current component
final ComponentAddress address = new ComponentAddress(this);
return new SomeClass() {
  IRender getRenderer(IRequestCycle cycle) {
    MyComponent component = (MyComponent) address.findComponent(cycle);
    // initialize variables in the component that will be used by the block here
    return new BlockRenderer(component.getComponent("block"));
  }
}

Since:
2.2
Version:
$Id: BlockRenderer.java 243791 2004-02-19 17:38:13Z hlship $
Author:
mindbridge

Constructor Summary
BlockRenderer(Block objBlock)
          Creates a new BlockRenderer that will render the content of the argument
 
Method Summary
 void render(IMarkupWriter writer, IRequestCycle cycle)
          The principal rendering/rewinding method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockRenderer

public BlockRenderer(Block objBlock)
Creates a new BlockRenderer that will render the content of the argument

Parameters:
objBlock - the Block to be rendered
Method Detail

render

public void render(IMarkupWriter writer,
                   IRequestCycle cycle)
Description copied from interface: IRender
The principal rendering/rewinding method. This will cause the receiving component to render its top level elements (HTML text and components).

Renderring and rewinding are the exact same process. The same code that renders must be able to restore state by going through the exact same operations (even though the output is discarded).

Specified by:
render in interface IRender
See Also:
IRender.render(IMarkupWriter, IRequestCycle)