MicroStrategy ONE

Block Renderers

Block renderers for the most typical text formats such as JSON and XML are available in MicroStrategy Web. Since a block is format-independent, it is possible to create other renderers and associate them with it.

The data retrieved from the Ajax request is typically presented using either of the formats below that generate an arbitrary hierarchical data structure.

  • JavaScript Object Notation (JSON)—Text format that represents the serialized form of a set of JavaScript objects. The JavaScript objects that may be represented in JSON include an Object (which is a generic associative array) and an Array (which is a one-dimensional vector of values).
  • XML—Text format that describes a hierarchical organization of elements. Each element may have any number of scalar attributes.

In MicroStrategy Web, the data is presented using the JSON format to generate the in-memory block tree.

The text format for rendering the block is specified in the server-side layout definition file as shown below.

Copy
<mstrlayout:layout>
    <mstrlayout:bContext defaultContentType="JSON" />
...
...

In a programmatic approach, the generateMarkup method of the Block class serializes the data retrieved from the Ajax request. This method requires a BlockContext object that provides the context for block serialization operations.

The BlockContext object uses the setDefaultContentType method to define the type of content to be generated. To generate markup that is suitable for JavaScript code, use the content type "JSON", as shown below.

Copy
// Create a BlockContext object…
BlockContext blockContext = new BlockContext();
// Indicate that we want JSON content…
blockContext.setDefaultContentType("JSON");
// Now, serialize the in-memory Block tree to JSON text
MarkupOutput markupOutput = Object.generateMarkup(blockContext);

The above code takes a previously defined “Object” block and gets the JSON text for it. This MarkupOutput object can be embedded in an HTML page or sent out as the response of a task.