You're reading from Bonita Open Solution 5.x Essentials
Bonita gives us the options to create two kinds of variables with regard to scope: pool variables and step variables. Pool variables are akin to global variables in any programming language and step variables correspond to the local variables of a function.
The type of variables, integers or text, are the same for both pool and step variables. Only their scope differs. For example, there might be an integer variable such as an ID number that might be required in all the steps of the workflow. We would have to make this a pool variable so that it can be accessed by all steps. On the other hand, one of the steps might have a field, called name
, which might be required only at that step. Hence, it makes sense to make name a step variable that is accessible only by that step.
To define a pool variable, select the pool and click on the Data tab in the details panel. We can add the variables by clicking on the Add... button. Similarly, to define a step variable...
The text variable is used to hold text of all kinds in Bonita. Note that this variable is of the type string of Java, found in java.lang.String
. The Multiplicity option is used to select whether the variable is a single string variable or an array of strings. We can also state the default value that this variable will take. If left blank, the variable will be initialized to null, the way Java Strings are initialized. This variable is used to store any kind of text value in Bonita.
The variable List of Options... contains a list of text variables that can be used in drop-down boxes or radio buttons. When we select the List of Options... as the data type, a box appears where we define the list that we want to populate. Let's name this list Smartphones
. Click on the Add... button, type in Apple
, and click on OK. Similarly, add more options. such as Samsung
, HTC
, and Nokia
. We can also rearrange the list options by clicking on the Up and Down tabs. After we have created the...
The date variable is used to store date values, for example, the date that the date-picker widget is in the Web application stores. It is of the Java type Date (java.util.Date
). In addition, while defining the default value of this variable, we are given the option to choose it from a date picker that displays the date and time in a grid fashion.
Also, the default value can be set to Now, which takes the date and time at execution. This feature is useful in most scenarios when we want to display the default date and time as the time when the end user comes across this variable.
The attachment variable is used to store any file attachment in Bonita. As the attachment is internally stored in the database as Binary Large Object (BLOB), this gives the flexibility to store any kind of file attachment, regardless of the extension.
The maximum size of the attachment can be 15 MB. The attachment variable is primarily used in the file widget while creating web forms. Whenever the user clicks on any file object from his system, it is uploaded into the Bonita database and stored as an attachment variable.XML Variable
.
Another way we can represent data in Bonita Studio is to use an XML variable to store data in the XML format. Relevant data can be represented in a concise way using XML. For creating this variable in Bonita, simply select the data type as XML. Here, we have to choose the XML namespace and element for the data. We can also add a new schema by importing an XSD file.
This variable is the most useful custom variable that Bonita provides. We have the ability to create Java classes and export them into a jar file from any IDE or Java command line. This jar file can be added to the classpath of Bonita. Thereafter, we can create a new Java object of the type of the class that we have created. Let us see how to do this:
Open up an IDE, such as IntelliJIdea or Eclipse. Create a new Java project and a package inside src. Here, we will name it
com.rohitbhat.examplepackage
. Inside this package, create a new class namedTestClass
. Enter the following code in it:public class TestClass { private String testString; private int testInt; public TestClass() { this.testString = ""; this.testInt = 0; } public String getTestString() { return testString; } public void setTestString(String testString) { this.testString = testString; } public int getTestInt() { return testInt; } public void setTestInt(int testInt...
We have looked through the various types of variables that are available for use in Bonita Studio. We now also know how to initialize these different kinds of variables, and also which variable to use in a particular context. Any kind of information that has to be saved in the workflow can be saved in different kinds of variables. In the next chapter, we will use these variables to create web forms.