MicroStrategy ONE

Styles and Beans

Web beans can have default and preference-based information included in their definition to specify the style that should be applied to the bean to render the content. The default style for a Web bean is always the first <style> element defined under the parent <styles> element. A preference-based style is specified in the preference attribute. The default style can be a preference-based style if it is the first <style> element defined. The name attribute of the <style> element serves a dual purpose. Its primary purpose is to act as the identifier of the <style> element itself, but when no preference attribute is included, it also specifies the style associated with this <style> element.

You can also specify a style for a bean in the displayBean custom tag used to render the bean for display, or in a <web-component> element of a <template> element in the Page Configuration file. Styles specified in these two ways override both the default and preference-based styles.

The code sample below illustrates a Web bean with two <style> elements defined in the Page Configuration file.

  • The first <style> element is the default style. Because no preference attribute is included, the name attribute is used to specify the style to be used, FolderStyleIcon. This must correspond to a style name in the Style Catalog Configuration file in order to be used.  

  • The second <style> element has a preference-based style defined. The value of the preference attribute corresponds to a user preference, which in turn references a style name. This referenced style name must correspond to a style name in the Style Catalog Configuration file in order to be used.

When a preference attribute exists, the name attribute simply identifies the <style> element.

Code sample for setting styles for a bean in the Page Configuration file:

<web-beanname="fb"sys-bean="FolderBean" persist-mode="2">

    <init-properties>...</init-properties>

    <request-properties>...</request-properties>

    <styles>

        <style name="FolderStyleIcon"/>

        <stylename="FolderStyleList"preference="folderViewMode"/>

    </styles>

</web-bean>

The <style> element for a Web bean is optional, but it accomplishes the following tasks if it is present:

  • If the code that renders the page does not indicate the style to be used, the default style of the bean is applied. If multiple <style> elements are defined by name only, the first becomes the default and the others are ignored.

  • You can include multiple <style> elements. If a specified style cannot be found or has a transform that is used with a different type of bean, the application will fail and display an error message.  

  • The preference attribute of the <style> element indirectly references a preference-based style to be used for rendering the bean. The value of the preference attribute is actually a preference name, and this preference name is associated with a style name in the preferences file, sys_definitions.xml. This file, located in the WEB-INF/xml folder, contains all of the values and references associated with preferences.

    • In the XML code sample above, a preference with the value folderViewMode is defined for the bean style. In this case, the name attribute is ignored and the value of the preference attribute (folderViewMode) is used to retrieve the name of the style referenced by that preference so that it can be used as the bean style.

    • If the style referenced by the preference folderViewMode does not exist or is empty, the application will fail and display an error message. In this case, the application will not use the name attribute to identify a style to be used.

MicroStrategy SDK provides a Web Customization Editor that can be used to associate a style with a bean (See Associating a Style with a Bean for detailed steps). The topic assumes you have a new style associated with a transform (See Creating a New Style and Associating a Transform with a Style). If you want to associate a new custom transform with the new style rather than using an existing transform, you must also create the custom transform (See Creating a New Transform). The code sample below illustrates the changes that need to be made to the Style Catalog Configuration file if you create a new style and associate it with a new transform.

The code samples below illustrates how the style for the Web bean defined in the code sample above can be overridden by the displayBean custom HTML tag used to render the bean.

JSP code sample or rendering the bean with the displayBean custom HTML tag:

<web:displayBeanbean="fb"styleName="custom_FolderStyleList"/>

 ASP.NET code sample or rendering the bean with the displayBean custom HTML tag:

<web:displayBean runat="server" bean="fb"styleName="custom_FolderStyleList"/>

See also