Useful Tools and Components: Using Variable Packages (VarPacks)

Example VarPack Uses

As explained on the previous page, custom VarPacks are used to provide access to configuration variables stored in an xml file. Two common places to use the VarPack would be a custom View (or Control) or a PEI.

For example, a custom VarPack could provide table cell width sizes. The code snippet below shows how to retrieve a value from the VarPack.

Java:

HelloWorldVarPack varPack;

varPack = (HelloWorldVarPack)

  m_asOwner.GetVarPack(HelloWorldVarPack.VARPACK_ID);

String strWidth=varPack.GetValueAsString("HelloWorldData","HelloWorldCellWidth");

myCell.SetWidth(strWidth);

C#:

HelloWorldVarPack varPack;

varPack = (HelloWorldVarPack)

   m_asOwner.GetVarPack(HelloWorldVarPack.VARPACK_ID);

StringstrWidth = varPack.GetValueAsString("HelloWorldData","HelloWorldCellWidth");

myCell.SetWidth(strWidth);

A custom VarPack could also be used in an ILoginActions PEI to do custom processing based on the current administrative folder. For example, you could do something like the code shown below.

Java:

IPTSessionptSession = (IPTSession) _oUserSession;

IApplicationapp = appData.GetApplication(); 

XMLBaseVarPack varPack;

varPack = app.GetVarPackManager().GetVariablePackage(HelloWorldVarPack.VARPACK_ID); 

intnFolderID = varPack.GetValueAsInt("HelloWorldData","HelloWorldFolderID"); 

if (ptSession.GetSessionInfo().GetCurrentUserAdminFolderID() == nFolderID)

{

   // Custom login code.

}

C#:

IPTSession ptSession = (IPTSession) _oUserSession;  

IApplication app = appData.GetApplication();  

XMLBaseVarPack varPack;

varPack = app.GetVarPackManager().GetVariablePackage(HelloWorldVarPack.VARPACK_ID);

int nFolderID = varPack.GetValueAsInt("HelloWorldData", "HelloWorldFolderID");

if (ptSession.GetSessionInfo().GetCurrentUserAdminFolderID() == nFolderID)

{

   // Custom login code.

}

Next: Step 1: Implementing the VarPack