Developing Java-Based Pagelets

This section provides overviews of how to develop pagelets in Java and Java pagelet development considerations and discusses how to:

  • Write business logic in Java.

  • Use Java to write business logic for a PeopleSoft or non-PeopleSoft system.

  • Invoke PeopleSoft components from Java.

Java is an extremely popular programming language today, especially for internet applications. PeopleTools provides support in several key areas to enable developers to create Java-based applications. Though the PeopleSoft development environment allows you to write PeopleSoft business logic in Java, the focus of the following sections is to provide information that is relevant to the developer who is integrating applications with the PeopleSoft Interaction Hub. An example is development that is being done to integrate your non-PeopleSoft application with the PeopleSoft Interaction Hub. Another example is a scenario in which you want to pull together data from your non-PeopleSoft system along with data from your PeopleSoft system for integration with the PeopleSoft Interaction Hub.

Two primary areas are available in which you can program in Java within the PeopleTools environment:

  1. Writing business logic in Java.

    You can use Java used to write business logic for PeopleSoft or non-PeopleSoft applications that are to be rendered in the PeopleSoft Interaction Hub. Java can be called from PeopleCode and the Java program can then reference the PeopleSoft runtime environment as needed.

    In addition, Pagelet Wizard facilitates Java development in that it enables the Java programmer to concentrate on business logic, while Pagelet Wizard handles all the development aspects of rendering the application in the portal framework without any coding necessary.

  2. Invoking PeopleSoft components from Java.

    All PeopleSoft components can be invoked from Java programs through the component interface technology. This is useful if you want to create Java servlets, applets, JSP programs, or Enterprise JavaBeans that invoke PeopleSoft business logic.

Another consideration when developing applications with Java is that any application developed by means of Java that is URL-addressable and produces HTML can be easily integrated into the PeopleSoft Interaction Hub through the PeopleSoft Interaction Hub registry functionality. This enables you to distribute your development and runtime environments making for better scalability for both.

For more information about leveraging the PeopleSoft Interaction Hub registry functionality to integrate your Java application with the PeopleSoft Interaction Hub, see the following documentation.

See Administering Pagelets in the Portal Registry.

These areas of Java programming within the PeopleTools development environment are discussed further in the following sections.

This section discusses the following Java development elements:

  • Business rules.

  • User interface.

  • User personalization.

  • Navigation.

  • Navigation on extended pages.

  • Portal integration.

Business Rules

Java can be used to apply business logic to data to create a result set. Pagelet Wizard can then be used to invoke the Java program. Parameters that are required by the Java program can be defined, managed, and passed to the Java program through Pagelet Wizard. These parameters may be derived from user personalization parameters, as well as administrator-defined parameters and system variables.

For example, the Java program may need the user’s ID, the user’s language, and the user’s personalization selection regarding whether to include historical transaction information or just current information. These parameters can be defined in Pagelet Wizard in relation to a Java class. Pagelet Wizard can access the PeopleSoft runtime environment to determine the user’s ID as well as other profile information, such as the user’s language.

See Understanding System Variables Supported as Data Source Parameters.

Pagelet Wizard will also manage the user interface and storage of user personalization data. This topic is discussed in detail in the subsequent User Personalization section. When the Java program is invoked, Pagelet Wizard will handle passing all required parameters to the Java program.

In addition, Java classes delivered with PeopleTools enable you to call PeopleCode from your Java program and access contextual information from the runtime system. If needed, business data can be retrieved, as necessary, through the numerous PeopleCode functions that are accessible from Java.

The result set created by the Java program may be in an HTML format or in an XML format. Pagelet Wizard will accept the output from the Java program and will manage the presentation of the information within the portal. This topic is discussed in the following User Interface section.

User Interface

Pagelet Wizard will manage all aspects of a pagelet’s user interface. No user-interface-related programming for the pagelet is required in the Java program. Pagelet Wizard can accept an HTML- or XML-based result set from a Java program. The HTML from the Java program can be rendered directly. Alternatively, XML can be transformed with XSL to create an appropriate pagelet user interface.

In either case, Pagelet Wizard will manage the XSL and invoke the transformation at runtime. Extensible Stylesheet Language templates are provided with Pagelet Wizard for general use scenarios. Extensible Stylesheet Language development may be required, depending on the specific user interface required for a pagelet.

See Defining Pagelet Wizard XSL Prototypes.

User Personalization

Pagelet Wizard supports the persistence of user personalization selections for a pagelet application and handles all aspects of the user interface that enable users to enter their preferences and selections. Personalization parameters are defined within Pagelet Wizard administration pages. No programming is required, Java or otherwise.

User personalization selections can occur at two levels. From the homepage, users can select which pagelet applications they want to include on their homepage. After they’ve selected a pagelet application and have decided where they want the pagelets to appear on their homepage, they can personalize a particular pagelet application.

Examples of user personalizations at the second level can include scenarios in which a user selects transactions from a particular region or chooses to include transactions using a particular date as opposed to same-day transactions.

The user interface for all of these activities, as well as the storage of the personalization data for persistence, is managed by Pagelet Wizard without any additional programming, Java or otherwise.

Pagelet Wizard supports functionality that enables an end user to select a pagelet application to appear on his or her homepage. When a pagelet application is registered with Pagelet Wizard, a folder, which represents a portal application category, can be selected. When users personalize their homepage by selecting specific pagelet applications that they want to appear on their homepage, the selection is presented within the category (folder) that is defined when they register the pagelet application through Pagelet Wizard.

See Step 6: Specifying Pagelet Publishing Options.

Pagelet Wizard also supports functionality that enables an end user to select values that allow a specific pagelet application to be personalized. The functionality may dictate that some input parameters that are required by a Java program be entered by an end user, while other parameters can be set by an administrator. Pagelet Wizard manages parameter passing and the user interface. Pagelet Wizard inspects the Java source code for input parameters. Pagelet Wizard administrators can then select which parameters can be accessed by an end user for personalization. The user interface to enables an end user to personalize a pagelet application and update the appropriate Java input parameters is automatically generated and managed by Pagelet Wizard.

Navigation

When creating links in your pagelet application that enable a user to navigate to a related page for details and so forth, the link may need to be proxied by the portal to keep the user within the portal. For example, if a pagelet link is not proxied, then the pagelet can take a user to a site that is completely independent from the portal. In this scenario, the navigational links on the portal header, the homepage menu pagelet, and the left-hand menu pagelet will not be available to the user.

If the link is proxied by the portal, then the link can access and display content from a site that is independent of the portal. However, the content will be rendered within the portal. For example, the portal’s header and left-hand menu will be available.

With the PeopleSoft Interaction Hub, links that are included in a pagelet will be altered automatically to support proxying by the portal. No programming is required, Java or otherwise.

Note: Content that is referenced by the link must be HTML-based to be rendered appropriately in the portal.

Navigation on Extended Pages

Clicking a link on an extended page displays content within the target frame. The PeopleSoft Interaction Hub, header, and left-hand menu area will remain. Therefore, the new content will be rendered in the context of the PeopleSoft Interaction Hub.

Note: Content that is referenced by the link must be HTML-based to be rendered appropriately in the portal.

The Return to Home link, which returns the user to the portal homepage, may be required from an extended page. The GenerateHomepagePortalURL function creates a URL string that represents an absolute reference to the portal homepage. Because you can access the PeopleSoft runtime environment from a Java program and you can access PeopleCode built-in functions, you can invoke the GenerateHomepagePortalURL function from your Java program.

See Developing Java-Based Pagelets.

See GenerateHomepagePortalURL

Portal Integration

The pagelet application needs to be integrated with the portal registry so that the pagelet application is managed, secured, and presented through the PeopleTools portal. Registration makes the portal aware of a pagelet. Information included in registration determines the name and security for your pagelet application. In addition, registration data determines the category in which the pagelet application resides. Users view pagelet applications within these categories when selecting items that they want to see on their homepage. No programming is required, Java or otherwise, to complete portal registration.

Many reasons exist why you would want to write business logic for your non-PeopleSoft applications (and even your PeopleSoft applications) in Java. Perhaps you have licensed a third-party set of Java classes to do some very specific processing (tax calculation, for example). Or perhaps you have developed some internal Enterprise JavaBeans for your specific business processes. Or perhaps you simply like to code in Java. Whatever the reason, you can easily integrate Java code with your applications through the Java PeopleCode functions.

Invoking Java from PeopleCode

Three primary Java PeopleCode functions are used to invoke Java from PeopleCode:

  • GetJavaClass

  • CreateJavaObject

  • CreateJavaArray

Java PeopleCode Function

Usage

Example

GetJavaClass

Finds a Java class that you can manipulate in PeopleCode. This is used for those classes that have static members for which instantiating an object of the class isn't appropriate. You can call only static methods, that is, class methods, with the object created with this function.

In Java, you access such static members of a class by using the class name:

result = java.class.name.SomeStaticMethod();

In PeopleCode, you use the following code:

&Result = GetJavaClass("java.class.name").
SomeStaticMethod();

The following example is simple PeopleCode that uses GetJavaClass to get a system class:

&Sys = GetJavaClass("java.lang.System");
&Sys.setProperty("java.security.policy", "C:\java\policy");
WinMessage("The security property is: " | 
&Sys.getProperty("java.security.policy"));
&Props = &Sys.getProperties();
&Props.put("java.security.policy", "C:\java\policy");
&Sys.setProperties(&Props);
WinMessage("The security property is: " | 
&Sys.getProperty("java.security.policy"));

CreateJavaObject

Creates a Java object that can be manipulated in your PeopleCode. You can use the CreateJavaObject function to create a Java array. If ClassName is the name of an array class (ending with [ ]), ConstructorParams are used to initialize the array.

In Java, use the following code to initialize an array:

intArray = new int[]{1, 2, 3, 5, 8, 13};

In PeopleCode, you use the following code to initialize a Java array:

&IntArray = CreateJavaObject("int[]", 1, 2, 3, 5, 8, 13);

If you want to initialize a Java array without knowing the number of parameters until runtime, use the CreateJavaArray function.

The following example is a simple PeopleCode program that creates a Java object from a sample program that generates a random password:

/* Example to return Random Passwords from a Java class */
Local JavaObject &oGpw;
/* Create an instance of the object */
&oGpw = CreateJavaObject("com.PeopleSoft.Random.Gpw_Demo");
&Q = "1";
/* Call the method within the class */
&NEW_VALUE = &oGpw.getNewPassword(&Q, PSRNDMPSWD.LENGTH);
/* This is just returning one value for now */
PSRNDMPSWD.PSWD = &NEW_VALUE;

CreateJavaArray

Enables you to create a Java array without knowing the number or value of the elements.

When you create an array in Java, you already know the number of elements in the array. If you don't know the number of elements in the array, but you want to use a Java array, use the CreateJavaArray function in PeopleCode. This will create a Java object that is a Java array, and you can pass in the number of elements that are to be in the array.

The following PeopleCode example passes a PeopleCode array of strings (&Parms) to a Java method xyz of class Abc. This example assumes that when you are writing the code, you don't know how many parameters you will have.

Local JavaObject &Abc, &RefArray;
Local array of String &Parms;
&Parms = CreateArray();
/* Populate array how ever you want to populate it */
&Abc = GetJavaObject("com.peoplesoft.def.Abc");
/* Create the java array object. */
&JavaParms = CreateJavaArray("java.lang.String[]",  &Parms.Len);
/* Populate the java array from the PeopleCode array. */
&RefArray = GetJavaClass("java.lang.reflect.Array");
For &i = 1 to &Parms.Len
	&RefArray.set(&JavaParms, &i - 1, &Parms[&i]);
End-For;
/* Call the method. */
&Abc.xyz(&JavaParms);

Accessing the PeopleSoft Runtime System from Java

After a Java class has been invoked, the class can access the PeopleSoft runtime system. Java classes delivered with PeopleTools enable you to call PeopleCode from your Java program and access contextual information from the runtime system, such as the current user’s role and language preference. By importing the PeopleTools-delivered Java classes in your Java program, you can have access to PeopleCode objects and methods. Hundreds of PeopleSoft system variables, constants, and built-in functions are available for use with this approach. Discussions of the various methods follow.

Accessing the runtime system works only from a Java program that was initially called from PeopleCode. You must call PeopleCode facilities only from the same thread that was used for the call into Java. You cannot call any PeopleCode facility that would cause the server to return to the browser for an end-user action because the state of the Java computation cannot be saved and restored when the action is complete.

Java Class

Usage

SysVar

Use to refer to PeopleSoft system variables, such as %Language or %Oprid.

For example, %Session, becomes SysVar.Session().

See System Variables.

SysCon

Use to refer to system constants, such as %SQLStatus_OK or %FilePath_Absolute.

For example, %CharType_Matched becomes SysCon.CharType_Matched.

See Constants.

Name

Enables you to use the PeopleSoft-reserved item references. This enables you to reference pages, components, records, fields, and so forth.

For example, you can refer to a record field using the following PeopleCode:

REC_NAME.FIELD_NAME

With the Name class, you can use a similar construct:

new PeopleSoft.PeopleCode.Name("REC_NAME", "FIELD_NAME");

As another example, you can refer to a PeopleSoft page using the following PeopleCode:

Page.PAGE_NAME

In Java, it would be:

new PeopleSoft.PeopleCode.Name("Page", "PAGE_NAME");

See Definition Name References.

Func

Use to refer to built-in PeopleCode functions, such as CreateRowset or GetFile.

For example, SetLanguage(LANG_CD) becomes Func.SetLanguage(LANG_CD).

The existing PeopleCode classes (Array, Rowset, and so forth) have properties and methods that you can access from Java. PeopleCode classes have the same name, so Record becomes Record, SQL becomes SQL, and so forth. Methods are accessed by the method name. The name of a property is prepended with either get or set, depending on whether you're reading or writing to the property. For example, to get the IsChanged property would be getIsChanged. To set the value for a field would be &MyField.setValue.

Func (continued)

Here is an example of a Java program that uses PeopleCode objects to access the database:

/* This code is used to test the Java/PeopleCode interface. */
import PeopleSoft.PeopleCode.*;
public class Test {
/*
* Add up and return the length of all the
* item labels on the UTILITIES menu,
* found two different ways.
*/
public static int Test() {
/* Get a Rowset to hold all the menu item records. */
Rowset rs = Func.CreateRowset(new Name("RECORD", "PSMENUITEM"), new Object[]{});
String menuName = "UTILITIES";
int nRecs = rs.Fill(new Object[]{"WHERE FILL.MENUNAME = :1", menuName});
int i;
int nFillChars = 0;
for (i = 1; i <= rs.getActiveRowCount(); i++) {
String itemLabel = (String)rs.GetRow(i)
.GetRecord(new Name("RECORD", "PSMENUITEM"))
.GetField(new Name("FIELD", "ITEMLABEL"))
.getValue();
nFillChars += itemLabel.length();
}
/* Do this a different way - use the SQL object to read each menu
item record. */
int nSQLChars = 0;
Record menuRec = Func.CreateRecord(new Name("RECORD", "PSMENUITEM"));
SQL menuSQL = Func.CreateSQL("%SelectAll(:1) WHERE MENUNAME = :2",
new Object[]{menuRec, menuName});
while (menuSQL.Fetch(new Object[]{menuRec})) {
String itemLabel = (String)menuRec
.GetField(new Name("FIELD", "ITEMLABEL"))
.getValue();
nSQLChars += itemLabel.length();
}
return nFillChars + 100000 * nSQLChars;
}
}

Func (continued)

This can be run from PeopleCode in the following way:

Local JavaObject &Test;
Local number &chars;
&Test = GetJavaClass("Test");
&chars = &Test.Test();
&Test = Null;
WinMessage("The character counts found are: " | &chars, 0);

See PeopleCode API Reference and PeopleCode Language Reference.

This section presents an example of pagelet application development for which the intention is that all programming be done in Java. Business logic might be for a PeopleSoft system or a non-PeopleSoft system. In this development example, PeopleTools programming is not required. All programming is done with Java.

The PeopleTools infrastructure can be leveraged without any PeopleTools programming through the use of PeopleSoft Interaction Hub features that support administration, integration, and implementation for the portal. The ability to leverage the PeopleTools infrastructure can significantly reduce the amount of Java programming that is required to develop a pagelet application for use in the PeopleSoft Interaction Hub.

Some of the information in this section is covered in other Pagelet Wizard documentation. The main difference in this section is that it presents the information as a development scenario as opposed to a feature description. Also, the ability to access the PeopleSoft runtime environment from Java is discussed in this section.

The following development scenario addresses the following elements of portal application development, integration, and implementation:

  • Business rules.

    Apply business logic and rules to data to create a result set.

  • User interface.

    Create the appropriate presentation format for a set of business data.

  • User personalization.

    • User personalization data.

      Allow pagelet applications to be selected by the end user to be placed on his or her homepage. Also, allow a user to personalize a specific pagelet application. These selections should persist.

    • User interface.

      Create the appropriate presentation format for personalization data.

  • Navigation for a pagelet.

    Create links on your pagelet to enable a user to navigate to a related page for details and so forth.

  • Navigation on extended pages.

    An extended page is a page that a user can get to from a homepage pagelet. Extended pages might show details as well as have links to enable a user to navigate to other related pages.

    • Links.

      Create links from your extended page to enable a user to navigate to a related page for further details and so forth.

    • Return links.

      Create links that enable the user to return to the portal’s homepage.

  • Portal integration and implementation.

    Integrate the pagelet application with the portal registry so that the pagelet application is managed, secured, and presented through the PeopleTools portal.

All PeopleSoft components can be invoked from Java programs through component interface technology. This is useful for developers who want to create Java servlets, applets, JSP programs, or Enterprise JavaBeans that invoke PeopleSoft business logic. This section provides an example of how to invoke a PeopleSoft component from Java. A Business Expense component is used as the example.

Creating the Component Interface

To expose a component to a third party, you must first create a component interface definition. You do this through the PeopleSoft Application Designer. Using drag-and-drop functionality, you can specify the properties and methods of the component that you want to expose. Numerous component interface definitions are delivered with the each PeopleSoft application.

Image: BUSINESS_EXPENSES component interface definition

The BUSINESS_EXPENSES component definition appears in the left frame in the following example. The properties and methods that are exposed through this interface are displayed in the right frame.

The following screenshot displays Bus_Exp component interface definition in the left frame and properties and methods in the right frame.

sm_BUSEXPComponentInterfaceDefinition7e36_tprt7aee

Image: SDK_BUS_EXP component interface

After the component interface definition is saved, you can then generate the Java classes for invoking this interface. You do this using the Generate Java Template command in PeopleSoft Application Designer:

The following screenshot illustrates an example of invoking the SDK_BUS_EXP component interface and generating Java classes.

sm_SDKBUSEXPComponentInterface7e35_tprt7af4

See Understanding Component Interface Class.

Invoking the Component Interface from Java

To invoke the Business Expense component interface from Java.

  1. Connect to the application server.

    To access a component interface, you need to establish a PeopleSoft session. To create a session object, use the Session.Connect () method. The Connect method, which takes five parameters, actually signs in to a PeopleSoft session. The Connect() method connects a session object to a PeopleSoft application server. Note that various options are available for using an existing connection and disconnecting and switching connections.

    import PeopleSoft.ObjectAdapter.*;
    import PeopleSoft.Generated.PeopleSoft.*;
    import PeopleSoft.Generated.CompIntfc.*;
    private ISession oSession;
    private CAdapter oAdapter;
    oAdapter = new CAdapter();
    oSession = new CSession(oAdapter.getSession());
    oSession.Connect(1,"//EHARRIS032000:9000","PTDMO","PTDMO",new byte[0]);
    
  2. Get an instance of the component interface.

    Use the GetComponent() method with a session object to get an instance of a previously created component interface.

    busExpense = new CBusExp( oSession.GetComponent( "BUS_EXP" ));
  3. Find an existing record.

    You can query a component interface to find relevant data instances based on primary and alternate search keys.

    busExpense.setName( searchDialogStrings[ 0 ]);
    busExpense.setLastNameSrch( searchDialogStrings[ 1 ]);
    busExpense.setEmplid( searchDialogStrings[ 2 ] );
    return( busExpense.Find() );
    
  4. Get an instance of data.

    GetKeys are the key values required to return a unique instance of existing data. GetKeys can be set by means of simple assignment to the properties of the component interface and then the Get() method can be invoked. This populates the component interface with data based on the key values that you set; this has been referred to here as a data instance.

    busExpense.setEmplid( getKey );
    boolean result = busExpense.Get();
    
  5. Migrate through collections of data.

    After getting a data instance, get access to the data in the component interface. PeopleSoft organizes component interface data within collections. Rows of data in a collection are called items.

    The following code creates a connection to the application server, gets the component interface, and fetches the first item in a collection.

    oAdapter = new CAdapter();
    oSession = new CSession(oAdapter.getSession());
    oSession.Connect(1,"//EHARRIS032000:9000","PTDMO","PTDMO",new byte[0]);
    busExpense = new CBusExp( oSession.GetComponent( "BUS_EXP" ));
    busExpense.setEmplid( getKey );
    boolean result = busExpense.Get();
    busExpenseFirstScrollItemCollection = busExpense.getBusExpensePer();
    busExpenseFirstScrollItem = firstScrollCollection.Item
    ( firstScrollIndex );
    return( busExpenseFirstScrollItem.getBusExpenseDtl() );
    
  6. Edit and access data in an item.

    Editing and accessing component interface data in Java is rather straightforward. The following Java code accesses the various public members of the class.

    long j = busExpenseSecondScrollCollection.getCount();
    Object [][] data = new Object[ ((int)j + 1) ][ 7 ];
    for( int i = 1; i < j + 1 ; i++ )
    {
    busExpenseSecondScrollItem = busExpenseSecondScrollCollection.Item( i );
    data[(i - 1)][0] = busExpenseSecondScrollItem.getBusinessPurpose();
    data[(i - 1)][1] = busExpenseSecondScrollItem.getChargeDt();
    data[(i - 1)][2] = busExpenseSecondScrollItem.getCurrencyCd();
    data[(i - 1)][3] = busExpenseSecondScrollItem.getDeptid();
    data[(i - 1)][4] = busExpenseSecondScrollItem.getExpenseAmt();
    data[(i - 1)][5] = busExpenseSecondScrollItem.GetPropertyByName
    ("ExpenseCd");
    data[(i - 1)][6] = busExpenseSecondScrollItem.GetPropertyByName
    ("CurrencyCd");
    }return( data );
    

    In the following example, data is accessed by means of the getNAME_OF_PRPERTY() method of an item or by means of the generic getPropertyByName() method. This code illustrates the way in which an entire collection of data can be captured and packaged into an object for transfer to a calling object.

    busExpenseFirstScrollItem.setEmplid( emplid );
    busExpenseFirstScrollItem.setExpensePeriodDt( expensePeriodDt );
    return( busExpense.Save() );
    

    Just as before, data is edited by means of item objects and the setNameOfPropery() method of those items. Also note that you needed to call the Save() method on the component interface to commit the changes.

  7. Insert an item into a collection and delete an item from a collection.

    Collection objects in Java contain the InsertItem() method in which the return value is the item that has just been inserted. After a new item is created, simply edit data in it and then remember to call the Save() method to commit the changes.

    busExpenseSecondScrollItem = busExpenseSecondScrollCollection.
    InsertItem( secondScrollIndex );

    Similarly, a DeleteItem() method is available:

    busExpenseSecondScrollCollection.DeleteItem( secondScrollIndex );
  8. Disconnect from a session.

    After a session is no longer needed, it should be disconnected from the application server. This is done by calling the Disconnect() method on the session object.

    oSession.Disconnect();