Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Validating Field Content

...

There are built-in validators available, and own, user-defined validator implementations can be used.

Dedicated validators may support configuration parameters:

<field type="..." variable="...">
...
<validator class="..." ...>
<configuration>
<param_1>...</param_1>
...
<param_n>...</param_n>
</configuration>
</validator>
</field>

The <configuration> section is optional.

For making migration easier, there can be used still <param name="..." value="..." /> entries instead or additionally to the newer <configuration> definition. This approach might be removed in one of the next major versions.

Parameter values may contain unresolved references to IzPack variables, which are resolved at installation time.

Using Validators

Validators are bound to user input fields using the nested <validator> element;

Code Block
languagehtml/xml
titleExample
<field type="text" variable="ora.db">
  <spec txt="SID:" id="text.oraclesettings.sid" size="3" set=""/>
  <validator class="com.izforge.izpack.panels.userinput.validator.NotEmptyValidator" txt="Invalid oracle SID!" id="text.oraclesettings.error.sid" />
</field>

Field validators can be combined with field processors. Validation takes place before the field processor applies:

Code Block
languagexml
titleExample
<field type="password" align="left" variable="keystore.password">
   <spec>
      <pwd txt="Keystore Password:" size="25" set=""/>
      <pwd txt="Retype Password:" size="25" set=""/>
      <processor class="com.izforge.izpack.panels.userinput.processor.PasswordEncryptionProcessor" backupVariable="keystore.password.plain">
         <configuration>
            <encryptionKey>xxx</encryptionKey>
            <algorithm>AES</algorithm>
         </configuration>
      </processor>
   </spec>
   <validator class="com.izforge.izpack.panels.userinput.validator.PasswordEqualityValidator"
              txt="Both keystore passwords must match." id="key for the error text"/>
   <validator class="com.izforge.izpack.panels.userinput.validator.PasswordKeystoreValidator"
              txt="Could not validate keystore with password and alias provided." id="key for the error text">
      <configuration>
         <keystoreFile>${ssl.keystore}</keystoreFile>
         <keystoreType>${ssl.keystore.type}</keystoreType>
         <keystoreAlias>${keystore.key.alias}</keystoreAlias>
         <skipValidation>${skip.keystore.validation}</skipValidation>
      </configuration>
   </validator>
</field>


Built-in Validators

...

You can implement your own custom Validator implementation simply by creating a new class which implements the com.izforge.izpack.panels.userinput.validator.Validator interface. This interface specifies a single method: validate(ProcessingClient) , which returns a boolean value. You can retrieve the value entered by the user by casting the input ProcessingClient for example in the RuleInputField and call the RuleInputField.getText() method. You can also retrieve any parameters to your custom Validator by calling theRuleInputField.getValidatorParams() which returns a java.util.Map object containing parameter names mapped to parameter values. For an example, take a look at com.izforge.izpack.util.RegularExpressionValidator.

...