Create Form Code Samples

This section provides code samples for working with the create form.

The following topics are discussed:

programHTMLOutput Sample

This sample shows Java code that can be used with a field type of programHTMLOutput. The code returns a string in XHTML format.

public String getObject(matrix.db.Context context, String [] 
args)
throws Exception
{
   HashMap paramMap = (HashMap)JPO.unpackArgs(args);
   HashMap requestMap = (HashMap)paramMap.get("requestMap");
   String objectId=(String)requestMap.get("objectId");
   MQLCommand objMQL  = new MQLCommand();
   objMQL.open(context);
   String sMQLStatement = "print bus "+ objectId +" select name 
dump |;";
   String objName = MqlUtil.mqlCommand(context,objMQL, 
sMQLStatement);
   objMQL.close(context);
   StringBuffer output=new StringBuffer();
   output.append("<a 
href=\"emxForm.jsp?form=type_Part&amp;objectId=");
   output.append(objectId);
   output.append("\" >");
   output.append(objName);
   output.append("</a>");
   return output.toString();
}
public String drawRadioButton(matrix.db.Context context, String 
[] args)
{
   StringBuffer output=new StringBuffer();
   output.append("<input type=\"radio\" name=\"gender\" 
value=\"male\"> Male </input>");
   output.append("<br></br>");
   output.append("<input type=\"radio\" name=\"gender\" 
value=\"female\"> Female </input>");
   return output.toString();
}

Connecting to an Object Sample

This sample shows an example of Java code to connect the newly-created object to another object.

public Object createAndConnect(Context context, String[] args)
throws Exception
{
  HashMap programMap = (HashMap) JPO.unpackArgs(args);
  HashMap paramMap = (HashMap) programMap.get("paramMap");
  String objectId = (String) paramMap.get("objectId"); //Part ID
  String newRDOId = (String) paramMap.get("New OID"); // RDO Id
  String strNewPartPartRevisionRelationship = "Design 
Responsibility";
//Connect the part to RDO
    if (!newRDOId.equals(""))
    {
       setId(newRDOId);
          DomainObject domainObjectToType = newInstance(context, 
objectId); //Part Object
          DomainObject domainObjectFromType = 
newInstance(context, newRDOId); //RDO Object
DomainRelationship.connect(context,domainObjectFromType,strNewP
artPartRevisionRelationship,domainObjectToType);
    }
    return new Boolean(true);
}