Sample JPO for Getting Field Values

The following is a sample Java Program Object (JPO) for getting the current vault for the object the form page currently pertains to.

You can use this type of JPO when the Field Type setting for a form field is set to program or programHTMLOutput. The getVault method processes the object and returns the vault value.

You can obtain the vault name by configuring the form field as a businessobject select expression "vault" instead of defining the Field Type=program. The "vault" example is used for simplicity and to illustrate the steps involved in writing the JPO for a form field.

/*
 * emxUIFormSample
 *
 * Copyright (c) 1992-2003 MatrixOne, Inc.
 *
 * All Rights Reserved.
 * This program contains proprietary and trade secret information of
 * MatrixOne, Inc.  Copyright notice is precautionary only and does
 * not evidence any actual or intended publication of such program.
 *
 * static const char RCSID[] = $Id: Exp $
 */
import matrix.db.*;
import matrix.util.*;
import java.io.*;
import java.util.*;
import com.matrixone.framework.beans.*;
import com.matrixone.framework.util.*;
import com.matrixone.framework.ui.*;
/**
 * @version AEF 9.5.0.0 - Copyright (c) 2002, MatrixOne, Inc.
 */
public class ${CLASSNAME}
{
    /**
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds no arguments
     * @throws Exception if the operation fails
     * @since AEF 9.5.0.0
     * @grade 0
     */
    public ${CLASSNAME} (Context context, String[] args)
        throws Exception
    {
        if (!context.isConnected())
            throw new Exception("not supported on desktop client");
    }
    /**
     * This method is executed if a specific method is not specified.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds no arguments
     * @returns nothing
     * @throws Exception if the operation fails
     * @since AEF 9.5.0.0
     */
    public int mxMain(Context context, String[] args)
        throws Exception
    {
        if (!context.isConnected())
            throw new Exception("not supported on desktop client");
        return 0;
    }
    /**
     * get Vault for the object.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds the following input arguments:
     *        0 - HashMap programMap
     * @returns StringList containing Vault name
     * @throws Exception if the operation fails
     * @since AEF 9.5.0.0
     */
    public static Object getVault(Context context, String[] args)
        throws Exception
    {
       HashMap programMap = (HashMap) JPO.unpackArgs(args);
     String objectId = (String)programMap.get("objectId");
        StringList vaultList = new StringList();
       StringList listSelect = new StringList(1);
        listSelect.addElement("vault");
        if ( objectId != null)
        {
            BusinessObject bo = new BusinessObject(objectId);
            bo.open(context);
            String vault = bo.getVault();
            bo.close(context);
            vaultList.addElement(vault);
        }
        return vaultList;
    }
   /**
     * set Vault for the objects.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds the following input arguments:
     *        0 - HashMap programMap
     * @returns vector of Vault names
     * @throws Exception if the operation fails
     * @since AEF 9.5.0.0
     */
    public static int setVault(Context context, String[] args)
    throws Exception
{
    // Map containing the request parameters
    HashMap requestMap = (HashMap) programMap.get("requestMap");
    // Map containing the key parameters
    HashMap paramMap = (HashMap) programMap.get("paramMap");
    String objectId = (String)paramMap.get("objectId");
    String newValue = (String)paramMap.get("New Value");
        if ( objectId != null && newValue != null)
        {
            // Vault newVault = new Vault(newValue);
            BusinessObject busObj = new BusinessObject(objectId);
            busObj.open(context);
            // busObj.setVault(context, newVault);
            BusinessObject newBusObj = busObj.change(context, busObj.getTypeName(), 
busObj.getName(), busObj.getRevision(), newValue, busObj.getPolicy().toString());
            busObj.close(context);
        }
        return (0);
    }
    
/**
     * get getOriginatorRange for the field.
     *
     * @param context the eMatrix <code>Context</code> object
     * @param args holds the following input arguments:
     *        0 - HashMap programMap
     * @returns StringList of Range values
     * @throws Exception if the operation fails
     * @since AEF 9.5.0.0
     */
    
    public static Object getOriginatorRange(Context context, String[] args)
        throws Exception
    {
       HashMap programMap = (HashMap) JPO.unpackArgs(args);
     String objectId = (String)programMap.get("objectId");
     // HashMap paramMap = (HashMap)programMap.get("paramList");
        System.out.println("objectId << " + objectId + " >>");
        StringList rangeList = new StringList();
        rangeList.addElement("Test SeniorDesignEngineer");
        rangeList.addElement("Test Everything");
        rangeList.addElement("Test DesignEngineer");
        rangeList.addElement("Test Buyer");
        System.out.println("rangeList << " + rangeList + " >>");
        return rangeList;
    }
}