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

Retrieving a specific bean from a PageComponent instance in Java using the MicroStrategy Web SDK


Tiago Siebler

Principal Product Specialist • Strategy


An addon provides access to a PageComponent instance during page execution, which can be used to access and manipulate a bean on that page. This example demonstrates how a bean can be retrieved from the PageComponent, if present, using a recursive loop.

An addon provides access to a PageComponent instance during page execution, which can be used to access and manipulate a bean on that page. This java snippet demonstrates how a specific bean can be retrieved from the PageComponent, if present, using a recursive loop. The same methodology can be applied for other beans found on the page, returning null if the bean could not be found.
SubscriptionBean:


// Fetch the SubscriptionBean from the page, if present
private SubscriptionBean getSubscriptionBean(WebComponent wc) {     
	SubscriptionBean result = null;   
	if (wc instanceof SubscriptionBean) { 
		System.out.println("wc.getname :"+wc.getName());
			result = (SubscriptionBean) wc;     
		} 
	else
		{      
		for (int i = 0; i < wc.getChildCount(); i++) {       
			result = getSubscriptionBean(wc.getChild(i));       
			if (result != null) break;      
		}     
	}     
	return result;
}

ReportBean:

// Fetch the ReportBean from the page, if present
private ReportBean getReportBean(WebComponent wc) {     
	ReportBean result = null;   
	if (wc instanceof ReportBean) { 
		System.out.println("wc.getname :"+wc.getName());
			result = (ReportBean) wc;     
		} 
	else
		{      
		for (int i = 0; i < wc.getChildCount(); i++) {       
			result = getReportBean(wc.getChild(i));       
			if (result != null) break;      
		}     
	}     
	return result;
}

Example usage within an addon:

// get the subscription bean from the page and do something with it
public void preCollectData(PageComponent page) {
	SubscriptionBean sb;
	try {
		sb = getSubscriptionBean(page);
		
		if(sb != null){
			// do something
			System.out.println("Subscription name: "+ sb.getSubscription().getName());
		}
		
	} catch (WebBeanException e) {
		e.printStackTrace();
	} catch (WebObjectsException e) {
		e.printStackTrace();
	}
}

 


Comment

0 comments

Details

Example

Published:

May 5, 2017

Last Updated:

May 5, 2017