Custom Input Field
Description
The custom input fields allows you to dynamically add or remove fields from the UserInputPanel with the click of a button.
The variable attribute defined for the custom field saves the number of rows submitted, (If two rows are submitted, variable would have value of 2).
The variable defined for the nested fields will become <variable>.<row_number> ( where the row number starts from 1 ).
Columns
<col> tags are used to add columns, they contain a field to be displayed.
Columns tags are nested within the <field type="custom" ... > tags.
Column tags may contain a validator that will validate based on all the values in the column.
The fields defined within the column tags can be defined exactly the same way as if you to define the field on its own, and can contain its own validation.
Note that the conditionid attribute for fields defined within the column tags are currently not supported.
Attributes to <field>
Attribute | Usage | Required | Default Value |
---|---|---|---|
variable | Defines the variable that will hold the number of rows submitted. | Yes | |
minRow | Defines the minimum amount of rows that must be displayed. | No | 1 |
maxRow | Defines the maximum amount of rows that must be displayed. | No | 5 |
conditionid | If the condition evaluates to show this field, otherwise hide this field. | No | Evaluates to true if undefined |
Currently, neither validators nor processors nested to each single <field>
element can be used. They will be ignored.
You can just use a per-column validator validating a comma-separated input like described above.
Validators
Attribute | Usage |
---|---|
com.izforge.izpack.panels.userinput.validator.UniqueValidator | Validate that all values in a column are unique |
If you are making your own column validator have a look at the source for UniqueValidator. You will realize that the values come in as a comma separated string.
The UniqueValidator has been made especially for validations in the Custom Input Field. It has no reasonable appliance for other input field types.
Examples
Simple example:
In the example below we define a custom field that that has three columns and atleast one row. The user may add up to three rows.
The first column will contain a combo box to select one or more creature types. It also validates that the selected creatures must be unique. (Ex. Mew cannot be chosen twice)
If creatures Mew and Pikachu were selected, it would be saved in creature.type.1 and creature.type.2 respectively.
The second column is similar to the first column except this combo box allows you to select a colour for your creature.
The third column specifies a text field for the user to submit a name for the selected creature. For each individual text field it validates that it is not empty.
Expand to see UserInputSpec.xml
<field type="custom" minRow="1" maxRow="3" variable="creature.count">
<spec>
<col>
<field type="combo" variable="creature.type" summaryKey="creature.type">
<description id="creature.type"/>
<spec id="creature.type">
<choice id="creature.type.1" value="Bulbasaur"/>
<choice id="creature.type.2" value="Charmander"/>
<choice id="creature.type.3" value="Geodude"/>
<choice id="creature.type.4" value="Mew"/>
<choice id="creature.type.5" value="Pikachu"/>
<choice id="creature.type.6" value="Squirtle"/>
</spec>
</field>
<validator class="com.izforge.izpack.panels.userinput.validator.UniqueValidator" id="creature.unique" />
</col>
<col>
<field type="combo" variable="creature.colour">
<description id="creature.colour"/>
<spec id="creature.colour">
<choice id="creature.colour.1" value="Blue"/>
<choice id="creature.colour.2" value="Green"/>
<choice id="creature.colour.3" value="Indigo"/>
<choice id="creature.colour.4" value="Orange"/>
<choice id="creature.colour.5" value="Red"/>
<choice id="creature.colour.6" value="Violet"/>
<choice id="creature.colour.7" value="Yellow"/>
</spec>
</field>
</col>
<col id="creature.name">
<field type="text" variable="creature.name" summaryKey="creature.name">
<spec id="creature.name" size="10"/>
<validator class="com.izforge.izpack.panels.userinput.validator.NotEmptyValidator" id="creature.name.empty" />
</field>
</col>
</spec>
</field>
Another example:
You can pre-set variables like this:
Expand to see install.xml
<variables>
<variable name="activemq.connection.count" value="1"/>
<variable name="activemq.connection.address.1" value="tcp://localhost:61616"/>
</variables>
and use it in the panel like this:
Expand to see UserInputSpec.xml
<field id="activemq.connection.panel.title" type="title"/>
<field align="left" id="activemq.connection.description" type="staticText"/>
<field type="space"/>
<field maxRow="10" minRow="1" type="custom" variable="activemq.connection.count">
<spec>
<col>
<field type="rule" variable="activemq.connection.address">
<spec default="tcp://localhost:7000" id="activemq.connection.url.label" layout="O:5:U :// O:15:U : N:5:5" resultFormat="displayFormat"/>
</field>
<validator class="com.izforge.izpack.panels.userinput.validator.UniqueValidator" id="activemq.connection.host.unique"/>
</col>
</spec>
</field>
In the above example, the active variable values take precedence over the values from the default attribute for prefilled values.
The default value is always the same for each row, the value of a preset variable can be specific to each row.
Screenshot of the panel resulting from this example: