PasswordField

This is a text field that displays echo characters instead of those entered by a user.

Component’s XML-name: passwordField.

Basics

The PasswordField is similar to TextField apart from the ability to set datatype. PasswordField is intended to work with text and entity attributes of type String only.

An example of the PasswordField:

<passwordField id="passwordField"
               caption="Secret password field"/>
@Autowired
private PasswordField passwordField;
@Autowired
private Notifications notifications;

@Subscribe("showPasswordBtn")
protected void onShowPasswordBtnClick(Button.ClickEvent event) {
    notifications.create()
            .withCaption(passwordField.getValue())
            .show();
}
password field

Attributes

  • The autocomplete attribute allows you to enable saving passwords in the web browser. It is disabled by default.

  • The capsLockIndicator attribute allows you to set the id of a CapsLockIndicator component that should indicate Caps Lock state for this passwordField.

Validation

To check values entered into the PasswordField component, you can use a validator in a nested validators element.

The following predefined validators are available for PasswordField:

In the example below, we will show a SizeValidator usage for passwordValidField:

<passwordField id="passwordValidField"
               caption="Secret password field">
    <validators>
        <size max="10" min="4"/>
    </validators>
</passwordField>

Events and Handlers

To generate a handler stub in Jmix Studio, select the component in the screen descriptor XML or in the Jmix UI hierarchy panel and use the Handlers tab of the Jmix UI inspector panel.

Alternatively, you can use the Generate Handler button in the top panel of the screen controller.

ContextHelpIconClickEvent

Validator

Adds a validator instance to the component. The validator must throw ValidationException if the value is not valid.

If you are not satisfied with the predefined validators, add your own validator instance:

@Install(to = "zipField", subject = "validator")
protected void zipFieldValidator(Integer value) {
    if (value != null && String.valueOf(value).length() != 6)
        throw new ValidationException("Zip must be of 6 digits length");
}

ValueChangeEvent

PasswordField XML Attributes

PasswordField XML Element