Block extension

The Visiativ Process development kit enables to define inside a block whose content will be created from a block extension.

The provided basic class simplifies the implementation of block extension classes. In the same way as the page extension class, this class possesses methods to directly access to the site module and to the execution context.

The block extensions processed in the context of building and displaying a page but only concerns the block itself.

A block extension enables to perform the following treatments:

  • the add of components and blocks when loading the page;
  • the position of bookmarks;

Block extension lifecycle

Before the page is not displayed to the user, the system triggers a certain number of events on the block being built.

onPrepareBlock(): this method is called with the block reconstructed in parameter. It is on this block that your components, and sub-blocks will be added.

onPrepareModel(): this method is called to let you position the values in the possible bookmarks on the block construction.

Implementing a block extension

To implement a block extension class, you just have to branch off the BasePageExtension class. The extension class must be declared in the properties of the affected block through the WYSIWYG designing tool of the page.

The full name is: com.axemble.vdoc.sdk.site.extensions.BaseBlockExtension.

Method of the basis class BaseBlockExtension

This basic class gives access to the site module and the execution context.

public abstract class BaseBlockExtension implements Serializable {
	final protected ISiteModule getSiteModule();
	final protected ISiteExecutionContext getExecutionContext();

	public int onPrepareBlock( IBlock rebuiltBlock );
	public void onPrepareModel( IRenderModel renderModel ) throws Exception;
}

Example of block extension implementation

The following example shows a block extension very simple that overloads the events triggered by the system.

This example provides a using case of both works that simplifies the handling of components and blocks:

  • The components work: contains the whole components provided by the product;
  • The blocks work: contains the whole blocks provided by the product;

It shows how to dynamically create a table, a row and cells and to position the bookmark value dynamically created too.

public class TableBlockExtension extends BaseBlockExtension {
	
	public int onPrepareBlock( IBlock rebuiltBlock ) {
		try {
			// creating a table
			TableBlock tableBlock = getSiteModule().getBlocksFactory().newTableBlock();
	
			//creating a table row
			TableRowBlock tableRowBlock = getSiteModule().getBlocksFactory().newTableRowBlock();
	
			// creating a cell
			TextComponent textComponent = getSiteModule().getComponentsFactory().newTextComponent();
			textComponent.setContent( "cellule 01" );
			tableRowBlock.addComponent( textComponent );
	
			// creating a second cell
			TextComponent textComponent2 = getSiteModule().getComponentsFactory().newTextComponent();
			textComponent2.setContent( "cellule 0${marker.number}" );
			tableRowBlock.addComponent( textComponent2 );
	
			tableBlock.addBlock( tableRowBlock );
	
			rebuiltBlock.addBlock( tableBlock );
	
			// only display the elements added to the rebuilded block
			return IRenderOptions.ONLY_CHILDREN;
		} catch( Exception e ) {}
		
		return super.onPrepareBlock( rebuiltBlock );
	}
	
	public void onPrepareModel( IRenderModel renderModel ) throws Exception {
		renderModel.setValue( "marker.number", "2" );
		super.onPrepareModel( renderModel );
	}
}

Javascript extension

The Process development kit offers also the possibility to respond to the events triggered by the system in Javascript.

The Process Javascript can be put in the affected block properties (WYSIWYG design tool).

Example of code in a Javascript block extension

The following example shows how respond to the Javascript events (equal to the ones present in the page extensions)

This example shows how to add an “Image " component by using the notion of « ProtocolURI ».

/**
* This method is called just before building the children (blocks and components).
*
* @param siteModule The site module object
* @param block The current block
* @param renderModel The render model to complete
*/
function onPrepareBlock(siteModule, block) {
	var protocolUri = siteModule.createProtocolSupport( "http://www.xxx.com/visiativ/resource/filecenter/document/02m-00000e-003/demo" );
	var imageComponent = siteModule.getComponentsFactory().newImageComponent();
	imageComponent.setHRef( protocolUri );
	imageComponent.setSourceRef( protocolUri );
	block.addComponent( imageComponent );
	return 2;
}

/**
* This method is called each time the block is about to be rendered.
*
* @param siteModule The site module object
* @param block The current block
* @param renderModel The render model to complete
*/
function onPrepareModel(siteModule, block, renderModel) {
}