MicroStrategy ONE

Server-side Layout Definition Files

While it is possible to construct a block programmatically, the recommended way is to use a server-side layout definition file for the content generation. Most of the server-side layout definition files used for rendering blocks are available as individual XML files in the WEB-INF\xml\layouts\blocks folder of the MicroStrategy Web installation.

The typical elements that are used for constructing block trees are described below. All the elements are within the mstrlayout namespace.

  • bContext—Creates a BlockContext object and specifies the type of content to be generated.
  • block—Creates an instance of a Block. It has a name attribute that refers to the name of the block to create.
  • bSetProperty—Sets a block property on the containing block. That is, a  bSetProperty appears as a child of the block element. The path refers to a named property in the block created by the enclosing block element.

The code in the server-side layout definition file has all the information required for constructing a block. That is, it contains information about the model block (data), view block (presentation) and the block renderer. In case of constructing a view block, the server-side layout definition file also contains information about which client-side layout definition file should be used for rendering the view block.

The server-side layout definition file works together with a transform to present the data. The transform class exposes a series of render methods that are each responsible for generating a small piece of the HTML. The server-side layout definition file is used to dynamically set block properties and the transform class generates the HTML.

Copy
The example below demonstrates how to construct an in-memory “Object” block tree using a server-side layout definition file. The “Object” block contains a composite property called objects that is a List of blocks of type Report.
<!DOCTYPE mstrlayout:layout SYSTEM "mstrlayout.dtd">
<mstrlayout:layout>
  <!-- Define our default content type to be JSON -->
  <mstrlayout:bContext defaultContentType="JSON" />
  <!-- Create a root Object block -->
  <mstrlayout:block name="Object">
     <!-- Set properties -->
     <mstrlayout:bSetProperty path="dssid" method="getDssID" />
     <mstrlayout:bSetProperty path="dsstp" method="getDssTP" />
     <mstrlayout:bSetProperty path="dssname" method="getDssName" />
     <mstrlayout:bSetProperty path="objects" method="getObject" />
     <!-- Set the 'objects' property to a single element list. -->
     <mstrlayout:bSetProperty path="objects">
         <mstrlayout:block name="Report">
             <!-- Set the properties… -->
             <mstrlayout:bSetProperty path="numRows" method="getNumRows" />
             <mstrlayout:bSetProperty path="numCols" method="getNumCols" />
         </mstrlayout:block>
     </mstrlayout:bSetProperty>
  </mstrlayout:block>
</mstrlayout:layout>

The Transform class that is associated with this server-side layout definition file needs to expose the following Java methods.

Copy
public String getDssID();
public integer getDssTP();
public String getDssName();
public List getObject();
// Assumed to operate on the first object in the “Object” block
public integer getNumRows();
public integer getNumCols();

It assumed that the last two methods implicitly operate upon the first object of the “Object” block.