Difference between revisions of "Document Template Classes"
imported>Aeric |
imported>Aeric |
||
Line 5: | Line 5: | ||
:* When a [[Print Template]] is processed, it gets its data from the [{{DOCHOST}}/javadocs/com/platform/api/TemplateContext.html TemplateContext] | :* When a [[Print Template]] is processed, it gets its data from the [{{DOCHOST}}/javadocs/com/platform/api/TemplateContext.html TemplateContext] | ||
:* Template reference | :* That object contains a HashMap for each kind of record that the Print Template can process. | ||
:* Retrieve a data object: <tt>TemplateContext.get("''objectName''");</tt> | |||
:*The TemplateContext contains the following standard HashMaps: | |||
::* ''objectName'' - Contains the data for the record the Print Template was invoked on | |||
::* <tt>createdUsr</tt> - The [[User]] object for the person who created the record. | |||
::* <tt>modifiedUsr</tt> - The [[User]] object for the person who most recently modified the record. | |||
:* To a Print Template, then, a data object is simply a HashMap that is present in the TemplateContext. | |||
:* That object is passed to a method in your Print Template class. By manipulating the HashMaps it contains, you change the data that the Print Template will be processing. | |||
In a Print Template, a data reference has the form <tt>$''objectName''.''fieldname''</tt>. In your code, you will do one or more of the following operations: | |||
:* Retrieve a data object from the TemplateContext: <tt>TemplateContext.get("''objectName''");</tt> | |||
:* Add or update a data object: <tt>TemplateContext.put("''objectName''", HashMap);</tt> | :* Add or update a data object: <tt>TemplateContext.put("''objectName''", HashMap);</tt> | ||
:* Get a field from data object: <tt>HashMap.get("''fieldName''");</tt> | :* Get a field from data object: <tt>HashMap.get("''fieldName''");</tt> | ||
:* Add or update a field in a data object: <tt>HashMap.put("''fieldName''",''value'');</tt><br>where <tt>''value''</tt> is typically a string or a nested HashMap. | :* Add or update a field in a data object: <tt>HashMap.put("''fieldName''",''value'');</tt><br>where <tt>''value''</tt> is typically a string or a nested HashMap. | ||
{{TBD|What are the other standard objects?}} | {{TBD|What are the other standard objects?}} |
Revision as of 21:44, 5 April 2012
This page is currently in progress...
About Print Template Classes
You can use a method in a Print Template Class to manipulate the data that a Print Template has available for processing. Here's how it works:
- When a Print Template is processed, it gets its data from the TemplateContext
- That object contains a HashMap for each kind of record that the Print Template can process.
- The TemplateContext contains the following standard HashMaps:
- To a Print Template, then, a data object is simply a HashMap that is present in the TemplateContext.
- That object is passed to a method in your Print Template class. By manipulating the HashMaps it contains, you change the data that the Print Template will be processing.
In a Print Template, a data reference has the form $objectName.fieldname. In your code, you will do one or more of the following operations:
- Retrieve a data object from the TemplateContext: TemplateContext.get("objectName");
- Add or update a data object: TemplateContext.put("objectName", HashMap);
- Get a field from data object: HashMap.get("fieldName");
- Add or update a field in a data object: HashMap.put("fieldName",value);
where value is typically a string or a nested HashMap.
__TBD: What are the other standard objects?__
Configuring a Print Template to use a Specified Class and Method
- --select the class, and the method to use
Methods that take following arguments are listed:
- com.platform.api.TemplateContext - The container that the print template gets its data from.
- String (objectName) - The name of the object the print template was invoked on.
- String (recordID) - The ID of the record on which it was invoked.
__TBD: TemplateContext is in new javadocs, yes? objectName is passed in, yes? Does return value have to be void?__
Accessing Lookup Target Records
__TBD: Is nested data stored like this?__ Data from lookup-target records is stored as a nested map. For example, to get data for the template variable $Order.customer.name:
- HashMap orderMap = TemplateContext.get("Order")
gets the Order HashMap from the context. - HashMap customerMap = orderMap.get("customer")
gets the lookup-target record for the customer field. - String name = customerMap.get("name")
gets the customer's name.
Examples
Changing Field Data
Example: Adding a New Field
Example: Adding a New Object
This code creates a new ProductSupplier "object" (as far as the Print Template is concerned), and adds it to the TenantContext (context).
public void procesData(TemplateContext context, String object,String record) { HashMap<String, Object> productSupplierMap = new HashMap<String, Object>(); map.put("supplierName", "Stuff R' Us"); map.put("phone", "408-555-0987"); context.put("ProductSupplier", productSupplierMap); }
After that method has run, the Print Template can use the variable $ProductSupplier.phone, just as though the data had originated in the platform.