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

KB35657: How to Determine the Total Count of Elements when using the WebElements API in the MicroStrategy Java Web SDK 9.3.1


Community Admin

• Strategy


This article discusses how to Determine the Total Count of Elements when using the WebElements API in the MicroStrategy Java Web SDK 9.3.1

The example provided in this document is provided “as-is” to the user and assumes that the user:

  • Can program, compile (e.g. javac, jikes, etc.), and execute Java programs
  • Can configure environment variables (e.g. JAR files, property files, etc.)
  • Have all the necessary tools to create Java applications (JDK, IDE, etc.)
  • Has access to the Strategy SDK documentation.
  • Has read the customization warning at the bottom of this document

 
PREREQUISITES:
 
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:

  • Strategy Web Universal (JSP): {web_root}/WEB-INF/lib directory.
  • Strategy Web (.NET): Program Files\Common Files\Strategy directory.

Note:
 
More elaborate programs will require additional library files and are out of the scope of this document.
 
 
The WebElementSource and WebElements API can be used to fetch a list of attribute elements to populate in a custom application. Sometimes a list of attribute elements can be quite large so a developer may find it feasible to fetch only a small amount of elements at a time. This is possible to do using the following method:
 
webElementSource.setBlockCount(10);
 
When adding the above method to the code, now only the first 10 elements will be returned to the WebElements collection. Sometimes it's necessary for the developer to still know the total amount of elements that are available.
 
 
The following sample demonstrates how to get the total count of Elements available event though only a small subset of elements is being fetched at a time:  
 
 
Java
package customclasses.misc;
import java.util.Enumeration;
import com.Strategy.web.objects.WebAttribute;
import com.Strategy.web.objects.WebAttributeForm;
import com.Strategy.web.objects.WebAttributeForms;
import com.Strategy.web.objects.WebElement;
import com.Strategy.web.objects.WebElementSource;
import com.Strategy.web.objects.WebElements;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.webapi.EnumDSSXMLAuthModes;
import com.Strategy.webapi.EnumDSSXMLObjectTypes;
 
public class GetElementsTotalSize  {
 
 public static void main(String[] args) throws WebObjectsException {  
  
        WebObjectsFactory objectFactory = WebObjectsFactory.getInstance();
        WebIServerSession serverSession = objectFactory.getIServerSession();
        serverSession.setServerPort(0);
        serverSession.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
        serverSession.setProjectName("Strategy Tutorial");
        serverSession.setLogin("administrator");
        serverSession.setPassword("");
        serverSession.setServerName("SERVERNAME");       
       
        try{                    
            WebObjectSource webObjectSource = serverSession.getFactory().getObjectSource();
           
            //Using the Subcategory attribute from Strategy Tutorial
            WebAttribute webAttribute = (WebAttribute)webObjectSource.getObject("8D679D4F11D3E4981000E787EC6DE8A4",EnumDSSXMLObjectTypes.DssXmlTypeAttribute,true);
           WebAttributeForms webAttributeForms = webAttribute.getForms();
        WebAttributeForm webAttributeForm = null;
        String attributesXML = "";
        for (int x= 0 ; x < webAttributeForms.size(); x++){
        webAttributeForm = webAttributeForms.get(x);
        if(webAttributeForm.getUseName().equals("ID"))
        attributesXML += "<oi did=\"" + webAttributeForm.getID() + "\"/>";
     
        }
        attributesXML = "<fct>" + attributesXML + "</fct>";
           
            WebElementSource webElementSource = serverSession.getFactory().getElementSourceObject();
            webElementSource.setObject(webAttribute);
            webElementSource.setAttributeFormsXML(attributesXML);
           
           
            //this will determine how many elements are returned in the fetch
            webElementSource.setBlockCount(10);           
           
            String resultXML = webElementSource.getElementsXML();
            System.out.println("xml: "+ resultXML);
           
            WebElements webElements = webElementSource.getElements();
           
            //this size variable will return 10 because of the block count setting above:           
            int size = webElements.size();
            System.out.println("Size of elements in fetch: "+ size);
           
            //this totalCount will return the total count of elements that are available, which will be 24 in this example:           
            int totalCount = webElements.getChildUnits().getChildCount();           
            System.out.println("Total count: "+ totalCount);           
           
            //iterating through the collection of elements returned:
            Enumeration enumeration = webElements.elements();
            while(enumeration.hasMoreElements()){
            System.out.println(((WebElement)enumeration.nextElement()).getElementID());
            }
           
            System.out.println("done");
          }
         
          catch (Exception ee) {
              ee.printStackTrace();
              } 
 }
}
 
 
 
 
 
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:

June 13, 2017

Last Updated:

June 13, 2017