The code samples in this section provide an example of how to use CJB files to display the following block in a custom tool.
Custom Tool Example
The following code sample provides the CJB file for the custom block example.
import com.mitratech.teamconnect.enterprise.api.custom.CustomTool; import com.mitratech.teamconnect.enterprise.api.model.Account;
public class MyCustomTool extends CustomTool { public void createAccount() { String accountName = "New Account"; BigDecimal allocationLimit = new BigDecimal(1000); Date startDate = new Date(); Date endDate = DateUtils.addYears(startDate, 1); Account newAccount = platform.getAccountService().newAccount(accountName, allocationLimit, startDate, endDate); platform.getAccountService().create(newAccount); } } |
Here's how the previous CJB sample works:
•The beginning of the code extends CustomTool, as shown in the following code.
public class MyCustomTool extends CustomTool |
•The sample accesses the AccountService class using the Platform class and creates a new account object called New Account.
String accountName = "New Account"; BigDecimal allocationLimit = new BigDecimal(1000); Date startDate = new Date(); Date endDate = DateUtils.addYears(startDate, 1); Account newAccount = platform.getAccountService().newAccount(accountName, allocationLimit, startDate, endDate); |
•The sample executes the create() method to create a new account from the tool.
platform.getAccountService().create(newAccount); |
The following code sample provides the XML file for the custom tool example. See Creating Block XML Files for more information about creating XML files.
<?xml version="1.0" encoding="UTF-8"?> <tc:transform version="1.0" xmlns:tc="http://www.w3.org/1999/XSL/Transform"> <input id="createAccount" name="createAccount" type="button" onclick="invokeToolAction('createAccount', 'createAccount');" title="<teamconnect:message key='button.yes'/>" value="<teamconnect:message key='button.yes'/>" /> </tc:transform> |
Here's how the previous XML sample works:
•When you save this XML file, you give it the same name as the Java file. The system knows that the XML file refers to the Java file of the same name.
•The <input> tag includes the following parts:
oThe ID, the name, and the type of <input> tag.
id="createAccount" name="createAccount" type="button" |
oThe onClick event with the invokeToolAction function. When you click the button, you call invokeToolAction, which submits the page and causes the method in the Java class to execute.
onclick="invokeToolAction('createAccount', 'createAccount'); |
oThe title and value of the button with a custom key that you can internationalize. To use this code, replace button.yes with a custom internationalization key for this button.
title="<teamconnect:message key='button.yes'/>" value="<teamconnect:message key='button.yes'/>" |