The string edit dialog is shown from the
action,
screen or
form component
editors when you click on the
[...] for a
Java code property.
-
The box above the edit area show the available parameters for the Java code property as well
as the return type. To get more information on classes from the com.install4j.* packages,
please see the install4j API javadoc and the
help topic for the install4j API.
A number of packages can be used with using fully-qualified class names. Those packages are:
- java.util.*
- java.io.*
- javax.swing.*
- com.install4j.api.*
- com.install4j.api.beans.*
- com.install4j.api.context.*
- com.install4j.api.screens.*
- com.install4j.api.actions.*
- com.install4j.api.formcomponents.*
- com.install4j.api.windows.*
- com.install4j.api.unix.*
You can put a number of import statements as the first lines in the text area in order to avoid using fully
qualified class names.
-
Java code properties can be
-
expressions
An expression doesn't have a trailing semicolon and evaluates to the required return type.
Example: !context.isUnattended() && !context.isConsole()
The above example would work as the condition expression of an action and skip the action for
unattended or console installations.
-
scripts
A script consists of a series of Java statements with a return statement of the
required return type as the last statement.
Example: if (!context.getBooleanVariable("enterDetails")) context.goForward(2, true, true); return true;
The above example would work as the validation expression of a screen and skip two screens forward
(checking the conditions of the target screen as well as executing the actions of the current screen)
if the variable with name "enterDetails" is not set to "true".
-
The primary interface to interact with the installer or uninstaller is the context which is always among
the available parameters. The context provides information about the current installation and gives access to
variables, screens, actions and other elements of the installation or uninstallation. The parameter is of
type
-
com.install4j.api.context.InstallerContext for screens and actions in the installation mode
-
com.install4j.api.context.UninstallerContext for screens and actions in the uninstallation mode
-
com.install4j.api.context.Context for form components.
Apart from the context, the action, screen or form component to which the Java code property belongs is
among the available parameters. If you know the actual class, you can cast to it and modify the object
as needed.
-
Screens, actions and form components are wired together with installer variables, please see the
help topic on screens and actions for more
information. Setting and getting installer variables is done through the context parameter with the
context.getVariable(String variableName) and
context.setVariable(String variableName, Object value) methods. The convenience method
context.getBooleanVariable(String variableName) makes it easier to check conditions.
Any object can be used as the value for a variable. To use installer variables in text properties
of actions, screens and form components, write them as
${installer:myVariableName}
.
-
It is advisable to test your expression or script after you change it. The
[Test] button will compile the
script and display any errors in a separate dialog.
Saving your script with the [OK]
button will not test the syntactic correctness of the script. Only when your project is compiled, the script
will then be compiled and errors will be reported.