EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB45806: How to Use a Style Mapper to Dynamically Change the Report Grid Style by Triggering an Event using the MicroStrategy Web SDK 9.4.1


Community Admin

• Strategy


Create a custom toolbar button that will change the report grid style from the default ReportGridStyle to a custom style, e.g. ReportGridStyleRomantic.

SCENARIO
 
Create a custom toolbar button that will change the report grid style from the default ReportGridStyle to a custom style, e.g. ReportGridStyleRomantic.
 
Before Click

ka04W00000147rxQAA_0EM440000002GXA.png

 
 
After Click

ka04W00000147rxQAA_0EM440000002GX5.png

 
 
Experienced developers may attempt to use the ReportBean's changeReportStyle event (4017). However, for reasons described below that will not work:

  1. Event 4017 is not actually used to change the style on the ReportBean; instead it is event 4096014 from the ViewBean that is used to change the style - event 4017 was probably used before the ViewBean was introduced, but now it has no function.
  2. The change style event 4096014 in the ViewBean actually refers to the autostyles which are defined in the metadata instead of the styleCatalog.
  3. The default ReportGridStyle is actually hardcoded into the layout file used to render the report (Report Execution) page. This means that any update to the ReportBean style in an event handler or an add-on will be "too early" in the page processing and will be overridden by the default style once the page loading is completed.

Use a custom Style Map and Style Mapper class to change the grid style. More information can be found in this MSDL sample here: https://resource.microstrategy.com/MSDZ/MSDL/AnalyticsEnterprise/docs/mergedProjects/websdk/topics/scenarios/Displaying_Different_Folder_Browsing_Page_Styles_Based_on_User_Groups.htm

  1. Create a toolbar item that invokes an event -- in this particular case, since it's already known that event 4017 is unused, it can be reused for this customization. (Alternatively, KB42491 can be followed to create a custom event.)
  2. Create a new style map for the ReportGridStyle. Create a new styler mapper class and set it as the map condition -- map to style field can contain "ReportGridStyleRomantic" or it can be dynamically retrieved from the Request Keys (more on that below).
  3. In the style mapper class, check the request keys using the StyleRequestContext by calling RequestKeys rk = context.getWebComponent().getBeanContext().getRequestKeys();
  4. From there, a check can be made to make sure it was event 4017 (or the developer's custom event) that was called, use the event parameter to set the style name, etc.; then call defaultResult.setWereConditionsMet(true) to indicate the style mapping should take place.

 
Sample Code for Style Mapper
 


/**
 * Strategy SDK Sample
 * Copyright © 2011 Strategy Incorporated. All Rights Reserved
 *
 * Strategy MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THIS SAMPLE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. Strategy SHALL NOT
 * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THIS SAMPLE CODE OR ITS DERIVATIVES.
 *
 *
 */

package com.Strategy.sdk.stylemappers;
import com.Strategy.web.beans.RequestKeys;
import com.Strategy.web.transform.StyleMapper;
import com.Strategy.web.transform.StyleMapperResult;
import com.Strategy.web.transform.StyleRequestContext;
import com.Strategy.web.transform.StyleMapperResultImpl;

public class SwapReportGridStyleMapper implements StyleMapper {

    static { System.out.println("Style Mapper called!"); }

    public StyleMapperResult mapStyle(String styleName, StyleRequestContext context, String addlData) {
        
        System.out.println("Method called: mapStyle");
        // Define the default result (false)
        StyleMapperResultImpl defaultResult = new StyleMapperResultImpl(false, null);
        RequestKeys rk = context.getWebComponent().getBeanContext().getRequestKeys();
        String evtID = rk.getValue("evt");
        
        if (evtID.equalsIgnoreCase("4017")) {
            System.out.println("Event 4017 detected!");
            defaultResult.setWereConditionsMet(true);
        }

        return defaultResult;
    }
}

 
 

ka04W00000147rxQAA_0EM440000002GX7.png

 
The example provided in this document is provided “as-is” and user has read the following customization warning:
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize several Strategy products and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy products or the process of customizing Strategy products, please refer to Strategy Developer Zone (https://developer.microstrategy.com).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/us/services/support/contact.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
 
 


Comment

0 comments

Details

Knowledge Article

Published:

March 31, 2017

Last Updated:

March 31, 2017