The preProcessJPO parameter specifies the name of the
JPO program and method to execute during pre-processing.
Example to invoke the emxForm.jsp with preProcessJPO:
${COMMON_DIR}/emxForm.jsp?mode=Edit&form=<form_name>
&preProcessJPO=<JPO Name>:<Method Name>
If you specify both a preProcessURL and preProcessJPO
are, the preProcessURL executes first followed by the preProcessJPO.
The pre-process JPO specifies the programMap as an argument for the
pre-processing. The programMap contains the following HashMaps:
- requestMap contains all the request parameters
- paramMap contains these key parameters and expected
values:l
- formMap contains all the field information
The above maps are packed using the packArgs method supported by JPO and
passed to the pre-process JPO being invoked. The pre-process JPO can
unpack this input parameter and use it for custom coding.
This code samples shows how to get the values for objectId, timeStamp,
relId, using a custom processing JPO.
// unpack the incoming arguments into a HashMap called 'programMap'
HashMap programMap = (HashMap)JPO.unpackArgs(args);
// get the 'paramMap' HashMap from the programMap
HashMap paramMap = (HashMap) programMap.get("paramMap");
// get the values for objectId, timeStamp, relId, EditAction from the paramMap
String objectId = (String) paramMap.get("objectId");
String timeStamp = (String) paramMap.get("timeStamp");
String relId = (String) paramMap.get("relId");
You can retrieve the individual field information by iterating
through the formMap as shown below.
MapList formFieldList = (MapList) formMap.get("fields");
for(int i=0; i<formFieldList.length(); i++)
{
HashMap fieldMap = (HashMap) formFieldList.get(i);
String field_expression = (String) fieldMap.get("expression_businessobject");
String fieldName = (String) fieldMap.get("name");
//Settings retrieval procedure
HashMap settingsMap = (HashMap) fieldMap.get("settings");
String fieldType = (String) settingsMap.get("Field Type");
}
The pre-process JPO returns a HashMap containing these
keys:
If the value of the Action key is CONTINUE, the system displays the
standard edit page. If the value of the Action key is STOP, the system
does not display the standard edit page.
If the MESSAGE key contains a value, the system displays as an alert
message on top of the editable page. When the user clicks OK in the message
dialog, the editable form page displays (if Action is Continue) or the
blank form closes (if Action is Stop).
When the blank window closes (when Action=STOP; MESSAGE contains a
value), do not call the onUnload event (cancelProcessJPO or cancelProcessURL).
The following example illustrates a custom pre-processing JPO method
that uses most of the pre/post/cancel processing features. See the code
comments for details:
public HashMap formPreProcObjReserve (Context context, String[] args) throws Exception
{
// unpack the incoming arguments
HashMap programMap = (HashMap)JPO.unpackArgs(args);
// initialize some variables
String reserveComment = "No Comment Available";
boolean objIsReserved = true;
String actionValue = "Stop";
// get the paramMap, and from it the objectId
HashMap paramMap = (HashMap) programMap.get("paramMap");
String objectId = (String) paramMap.get("objectId");
// get the current user's name
String currentUser = PersonUtil.getFullName(context);
String userId = (String) PersonUtil.getPersonProperty(context,"id");
DomainObject userObject = new DomainObject(userId);
String userName = userObject.getInfo(context,DomainConstants.SELECT_NAME);
// build the selects for the current object
BusinessObjectWithSelect selectList = null;
StringList objectSelects = new StringList();
objectSelects.addElement("reserved");
objectSelects.addElement("reservedby");
objectSelects.addElement("reservedstart");
objectSelects.addElement("reservedcomment");
objectSelects.addElement(DomainConstants.SELECT_TYPE);
objectSelects.addElement(DomainConstants.SELECT_NAME);
objectSelects.addElement(DomainConstants.SELECT_REVISION);
// create a BusinessObject for the current object, open the BusinessObject,
// get the selects, close the BusinessObject
BusinessObject busObject = new BusinessObject(objectId);
busObject.open(context);
selectList = busObject.select(context,objectSelects);
busObject.close(context);
// get the object's reserved status from the select results
String isReserved = selectList.getSelectData("reserved");
String reservedBy = selectList.getSelectData("reservedby");
String reservedStart = selectList.getSelectData("reservedstart");
String reservedComment = selectList.getSelectData("reservedcomment");
// get the object's TNR from the select results
String objType = selectList.getSelectData("type");
String objName = selectList.getSelectData("name");
String objRev = selectList.getSelectData("revision");
// initialize some constants that will be used in the Message string
String messageString = "Unknown";
String ALERT_SEPARATOR_STRING = " -----------------------------";
String NEWLINE_CHAR = System.getProperty("line.separator");
String TAB_CHAR = "\t";
// set the reserved boolean, depending on whether the object is already reserved
if(isReserved.equals("TRUE")){
objIsReserved = true;
} else {
objIsReserved = false;
}
// if the object is already reserved
if(objIsReserved){
// determine if the current user made the reservation. set the Action
// key accordingly (Continue if this user made the reservation, Stop if not)
if(reservedBy.equals(userName)){
actionValue = "Continue";
} else {
actionValue = "Stop";
}
// build the Message string (all users will get this Message,
// but the Action key will differ depending on user)
messageString = "";
messageString = "----- This object is already Reserved -----";
messageString += NEWLINE_CHAR;
messageString += "Name: " + TAB_CHAR + objName;
messageString += NEWLINE_CHAR;
messageString += "Type: " + TAB_CHAR + objType;
messageString += NEWLINE_CHAR;
messageString += "Rev: " + TAB_CHAR + objRev;
messageString += NEWLINE_CHAR;
messageString += ALERT_SEPARATOR_STRING;
messageString += NEWLINE_CHAR;
messageString += "Reserved by: " + TAB_CHAR + reservedBy;
messageString += NEWLINE_CHAR;
messageString += "When reserved: " + TAB_CHAR + reservedStart;
messageString += NEWLINE_CHAR;
messageString += "Comment: " + TAB_CHAR + reservedComment;
messageString += NEWLINE_CHAR;
messageString += ALERT_SEPARATOR_STRING;
messageString += NEWLINE_CHAR;
messageString += "Current user:"+ TAB_CHAR + userName;
messageString += NEWLINE_CHAR;
messageString += "\'Action\' key:"+ TAB_CHAR + actionValue;
messageString += NEWLINE_CHAR;
messageString += ALERT_SEPARATOR_STRING;
messageString += NEWLINE_CHAR;
}
// if the object is not already reserved
if(!objIsReserved){
// set the Action key to 'Continue'
actionValue = "Continue";
// build a Comment string to include in the reserve operation
reserveComment = "Reserved by " + userName;
// open the BusinessObject, reserve the object, close the BusinessObject
busObject.open(context);
busObject.reserve(context,reserveComment);
busObject.close(context);
// build the Message string
messageString = "";
messageString = "------ You have Reserved this object ------";
messageString += NEWLINE_CHAR;
messageString += "Name: " + TAB_CHAR + objName;
messageString += NEWLINE_CHAR;
messageString += "Type: " + TAB_CHAR + objType;
messageString += NEWLINE_CHAR;
messageString += "Rev: " + TAB_CHAR + objRev;
messageString += NEWLINE_CHAR;
messageString += ALERT_SEPARATOR_STRING;
messageString += NEWLINE_CHAR;
messageString += "\'Action\' key:"+ TAB_CHAR + actionValue;
messageString += NEWLINE_CHAR;
messageString += ALERT_SEPARATOR_STRING;
messageString += NEWLINE_CHAR;
}
// build the return HashMap (containing the Action and Message keys)
HashMap returnMap = new HashMap(2);
String actionKey = "Action";
String messageKey = "Message";
returnMap.put(actionKey,actionValue);
returnMap.put(messageKey,messageString);
// send the return HashMap back to the Form component
return returnMap;
} //end of the formPreProcObjReserve method