UserInputPanel
When you need to capture user input that will be available to your installer then you need to use the UserInputPanel.
This panel allows you to prompt the user for data that you can use later in the installation process.
Resource "userInputSpec.xml"
The UserInputPanel is described in an XML file that you create and list as a resource with the id "userInputSpec.xml"
Then you can list it in a <panel> element with the class name "UserInputPanel".
<resources> <res id="userInputSpec.xml" src="user_input_spec.xml" parse="yes" type="xml"/> </resources> ... <panels> ... <panel classname="UserInputPanel" id="panel1"/> ... </panels>
A UserInputPanel can be highly dynamic, since it will be refreshed every time the user input changes and will be rendered based on conditions.
For instance, it would be possible to enable or disable some options by clicking a checkbox.
The user input panel can be populated with UI elements. The specification supports text labels, input elements, explanatory text and some minor formatting options.
<izpack:userinput version="5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:izpack="http://izpack.org/schema/userinput" xsi:schemaLocation="http://izpack.org/schema/userinput http://izpack.org/schema/5.0/izpack-userinput-5.0.xsd"> <panel id="panel1"> <field type="staticText" align="left" txt="Enter the Information required to connect to your proxy" id="input.title"/> <field type="text" variable="proxyaddress"> <spec txt="Proxy Host:" id="input.proxy" size="25" set=""/> </field> <field type="text" variable="proxyPort"> <spec txt="Proxy Port:" id="input.port" size="6" set=""/> </field> <field type="text" variable="proxyUsername"> <spec txt="Proxy Username:" id="input.username" size="20" set=""/> </field> <field type="password" variable="proxyPassword"> <spec> <pwd txt="Proxy Password:" size="20" set=""/> </spec> </field> </panel> </izpack:userinput>
The following types of user input elements are supported:
- Text
- Combo Box
- Radio Buttons
- Check Box
- Password
- File
- Multiple files
- Directory
- Rule Input Field
- Search Field
- Button
- Custom
Additionally visual elements can be added using the following types:
- Static Text
- Title
- Space
- Divider
There is a more complex example of a userInputSpec.xml at Sample userInputSpec.xml showing 3 panels. There are some advanced features in this example, but the general flow should be looked at first.
Accessing User Input
User input is not directly inserted into your configuration files but the variables that you specify for this panel are set in the variable substitution system. After the user has completed filling in the UserInputPanel, the variables and associated values are available for substitution.
This process has a number of implications of which you should be aware.
- Not only can you set additional variables in this way but you can also modify variables that are defined elsewhere - even built in variables. For this reason you should be careful to avoid conflicts when choosing variable names. Although there might be cases when it seems useful to modify the value of other variables, it is generally not a good idea to do so. Because you might not exactly know when other variables are set and when and where they are used throughout the installation process, there might be unintended side effects.
- The panel must be shown before the variables are used. In most cases you will use the values to substitute variables in launch and configuration files that you supply with your installation. For this to work you place this panel before the install panel, because the install panel uses the variable substitutor to replace all such variables. Although invoking this panel any later in the process will correctly set the variables internally, it will be too late to affect the files written to disk.
- You can also use variables set in this way in other panels that you have written yourself.There is a section in the chapter on writing your own panel that explains how to do this. Also in this case it is important to place the input panel in the process before the variables are used.
Hiding fields
It is possible to hide every field element based on conditions.
It is also possible to hide selected elements on the panel or to hide the panel altogether if certain packs are not selected. For this to work you must place this panel after the packs panel. One side effect of using this feature is that it is not possible to step back once the user input panel is displayed. This is because the user might make changes in the packs selection that would require a complete rebuild of the UI. Unfortunately, building the UI is an irreversible process, therefore the user can not be allowed to go back to the packs panel.
XML Structure for the UserInputPanel Definition
A UserInputPanel is defined in a separate descriptor file, referred to in the src
attribute in the resource "userInputSpec.xml" in the installation descriptor.
<izpack:userinput version="5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:izpack="http://izpack.org/schema/userinput" xsi:schemaLocation="http://izpack.org/schema/userinput http://izpack.org/schema/5.0/izpack-userinput-5.0.xsd"> <panel id="panel1"> <field .../> <field .../> ... </panel> ... </izpack:userinput>
The top level XML element is <userInput>
. For most requirements it does not make sense to include more than one <panel>.
However, you might want to present multiple user input panels - with different content of course. Therefore the <userInput>
section can contain multiple <panel>
tags that each specify the details for each panel instance.
The <panel> Element
The tag name for this is <panel>
. The <panel>
tag uses the following attributes:
Name | Required | Description | Values |
---|---|---|---|
| yes | This is the id of the user input panel for which this specification should be used. This id links to the panel specification in the install.xml file. | String Value |
| no | Sets the alignment of fields used in the panelThere are three general layout rules this panel uses, they are | left, center, right default: left |
| no | Normally the user input is shown with a small border. To prevent this border set this attribute to | true, false default: true |
| no | This can be used to set the column width of the two column layout. This value is in percent of the whole size. If it is set to | 0-100 percent default: 0 |
summaryKey | no | Id of a string that represents what header name to display in the SummaryPanel of the UserInputPanel. This attribute must be defined if you would like to summarize information about the user input in this panel in the SummaryPanel.. Note that you will have to add the summaryKey attribute to the fields you would like those to show up in the SummaryPanel as well. | String Value |
readonly | no | The | true, false default: false |
readonlyCondition | no | The | true, false default: false |
displayHidden | no | Setting Displayed hidden fields are disabled (ie. "greyed out") . But if the condition of the panel evaluates to false, display all fields on the panel just as disabled instead of hiding it. | true, false default: false |
displayHiddenCondition | no | The | true, false default: false |
rigid | no | When set to "true", the topBuffer will represent a number of pixels rather than a percentage. | true, false default: false |
topBuffer | no | Represents the percentage of leftover vertical space to place on top of the components. Setting | Integer default: 25 |
Nested Elements
Name | Required | Description | Values |
---|---|---|---|
createForPack | no | If this tag is present the appropriate user input panel gets activated just if the mentioned pack is selected by the user in the PacksPanel. | Valid pack names, see PacksPanel. |
createForUnselectedPack | no | If this tag is present the appropriate user input panel gets activated only if the mentioned pack is not selected by the user in the PacksPanel . | Valid pack names, see PacksPanel. |
os | no | Operating system-specific constraints. | Valid OS constraints, see OS Restrictions. |
field | no | One or more user input field definitions, described on the page Fields. | Valid user input field definitions, see Fields for more information. |
Internationalization
To provide internationalization, you create a file named userInputLang.xml_xyz
where xyz
is the ISO3 code of the language in lowercase. Please be aware that case is significant. This file has to be inserted in the resources section of install.xml
with the id
and src
attributes set at the name of the file.
Example:
If you have the following userInputSpec.xml and you want to internationalize input.comment
, input.proxy
, input.port
for English and French you have to create two files named userInputLang.xml_eng and userInputLang.xml_fra:
<izpack:userinput version="5.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:izpack="http://izpack.org/schema/userinput" xsi:schemaLocation="http://izpack.org/schema/userinput http://izpack.org/schema/5.0/izpack-userinput-5.0.xsd"> <panel id="panel1"> <field type="staticText" align="left" txt="My comment is here." id="input.comment"/> <field type="text" variable="proxyaddress"> <spec txt="Proxy Host:" id="input.proxy" size="25" set=""/> </field> <field type="text" variable="proxyPort"> <spec txt="Proxy Port:" id="input.port" size="6" set=""/> </field> </panel> </izpack:userinput>
<izpack:langpack version="5.0" xmlns:izpack="http://izpack.org/schema/langpack" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://izpack.org/schema/langpack http://izpack.org/schema/5.0/izpack-langpack-5.0.xsd"> <str id="input.comment" txt="My comment is here."/> <str id="input.proxy" txt="Proxy Host Name:"/> <str id="input.port" txt="Proxy Host Port:"/> </izpack:langpack>
<izpack:langpack version="5.0" xmlns:izpack="http://izpack.org/schema/langpack" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://izpack.org/schema/langpack http://izpack.org/schema/5.0/izpack-langpack-5.0.xsd"> <str id="input.comment" txt="Mon commentaire est ici"/> <str id="input.proxy" txt="Nom de l'hôte proxy:"/> <str id="input.port" txt="Port de l'hôte proxy:"/> </izpack:langpack>
you will also have to add the following to the install.xml file
<resources> ... <res id="userInputSpec.xml" src="userInputSpec.xml"/> <res id="userInputLang.xml_eng" src="userInputLang.xml_eng" /> <res id="userInputLang.xml_fra" src="userInputLang.xml_fra" /> ... </resources>