Example usage for com.vaadin.data.validator StringLengthValidator setMinLength

List of usage examples for com.vaadin.data.validator StringLengthValidator setMinLength

Introduction

In this page you can find the example usage for com.vaadin.data.validator StringLengthValidator setMinLength.

Prototype

public void setMinLength(Integer minLength) 

Source Link

Document

Sets the minimum permissible length.

Usage

From source file:edu.kit.dama.ui.commons.util.UIUtils7.java

License:Apache License

/**
 * Create a text area with the provided properties. The size is set to
 * SizeFull and the text area is set to 'immediate' (show changed immediately
 * to the user)./*w w  w .  ja  v a 2 s .c om*/
 *
 * @param pCaption The caption
 * @param pInputPrompt The input prompt shown if no value is set
 * @param pMinLength The min. string length of the text area. The content can
 * be checked during validation.
 * @param pMaxLength The max. string length of the text area. The content can
 * be checked during validation.
 *
 * @return The text area
 */
public static TextArea factoryTextArea(String pCaption, String pInputPrompt, int pMinLength, int pMaxLength) {
    TextArea theArea = new TextArea();
    theArea.setCaption(pCaption);
    theArea.setImmediate(true);
    theArea.setSizeFull();
    theArea.setInputPrompt(pInputPrompt);
    theArea.setNullSettingAllowed(false);
    theArea.setNullRepresentation("");
    StringLengthValidator val;
    if (pMinLength > 0) {
        val = new StringLengthValidator("The content length of this text area must be between " + pMinLength
                + " and " + pMaxLength + " characters.");
        val.setMinLength(pMinLength);
    } else {
        val = new StringLengthValidator(
                "The maximum content length of this text area is " + pMaxLength + " characters.");
    }

    val.setMaxLength(pMaxLength);
    theArea.addValidator(val);
    return theArea;
}

From source file:edu.kit.dama.ui.commons.util.UIUtils7.java

License:Apache License

/**
 * Create a text field with the provided properties. In addition, the returned
 * text field won't allow to set 'null' values by the user and has no
 * null-representation. Therefore it shows the input prompt when no value is
 * provided. The height of the text field is left to the default value
 * ('undefined').//from   w  w  w . java 2  s .  c o m
 *
 * @param pCaption The field caption.
 * @param pInputPrompt The input prompt shown if no value is set.
 * @param pWidth The field width (e.g. 100% or 60px).
 * @param pImmediate The value of the 'immediate' flag.
 * @param pMinLength The min. string length of the text field. The content can
 * be checked during validation.
 * @param pMaxLength The max. string length of the text field. The content can
 * be checked during validation.
 *
 * @return The text field
 */
public static TextField factoryTextField(String pCaption, String pInputPrompt, String pWidth,
        boolean pImmediate, int pMinLength, int pMaxLength) {
    TextField theField = new TextField();
    theField.setCaption(pCaption);
    theField.setImmediate(pImmediate);
    theField.setWidth(pWidth);
    theField.setInputPrompt(pInputPrompt);
    theField.setNullSettingAllowed(false);
    theField.setNullRepresentation("");

    StringLengthValidator val;
    if (pMinLength > 0) {
        val = new StringLengthValidator("The content length of this text field must be between " + pMinLength
                + " and " + pMaxLength + " characters.");
        val.setMinLength(pMinLength);
    } else {
        val = new StringLengthValidator(
                "The maximum content length of this text field is " + pMaxLength + " characters.");
    }
    val.setMaxLength(pMaxLength);
    theField.addValidator(val);
    return theField;
}

From source file:edu.kit.dama.ui.commons.util.UIUtils7.java

License:Apache License

/**
 * Create a password field with the provided properties. In addition, the
 * returned password field won't allow to set 'null' values by the user and
 * has no null-representation. As this is a password field, no input prompt is
 * shown. The height of the text field is left to the default value
 * ('undefined')./* ww  w. ja v a 2 s .co m*/
 *
 * @param pCaption The field caption.
 * @param pWidth The field width (e.g. 100% or 60px).
 * @param pImmediate The value of the 'immediate' flag.
 * @param pMinLength The min. string length of the text field. The content can
 * be checked during validation.
 * @param pMaxLength The max. string length of the text field. The content can
 * be checked during validation.
 *
 * @return The text field
 */
public static PasswordField factoryPasswordField(String pCaption, String pWidth, boolean pImmediate,
        int pMinLength, int pMaxLength) {
    PasswordField theField = new PasswordField();
    theField.setCaption(pCaption);
    theField.setImmediate(pImmediate);
    theField.setWidth(pWidth);
    theField.setNullSettingAllowed(false);
    theField.setNullRepresentation("");

    StringLengthValidator val;
    if (pMinLength > 0) {
        val = new StringLengthValidator("The content length of this text field must be between " + pMinLength
                + " and " + pMaxLength + " characters.");
        val.setMinLength(pMinLength);
    } else {
        val = new StringLengthValidator(
                "The maximum content length of this text field is " + pMaxLength + " characters.");
    }
    val.setMaxLength(pMaxLength);
    theField.addValidator(val);
    return theField;
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.component.LoginDialog.java

License:Apache License

public void init() {
    //Layout//ww w . j a v a  2  s.c  om
    FormLayout layout = new FormLayout();
    setContent(layout);
    HorizontalLayout hlayout = new HorizontalLayout();
    hlayout.addComponent(loginButton);
    hlayout.addComponent(cancelButton);
    layout.addComponent(name);
    layout.addComponent(password);
    name.focus();
    name.setWidth(100, Unit.PERCENTAGE);
    StringLengthValidator nameVal = new StringLengthValidator(Lookup.getDefault()
            .lookup(InternationalizationProvider.class).translate("password.length.message"));
    nameVal.setMinLength(5);
    name.addValidator(nameVal);
    name.setImmediate(true);
    StringLengthValidator passVal = new StringLengthValidator(
            Lookup.getDefault().lookup(InternationalizationProvider.class).translate("password.empty.message"));
    passVal.setMinLength(3);
    password.addValidator(passVal);
    password.setImmediate(true);
    password.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(hlayout);
    layout.setComponentAlignment(name, Alignment.TOP_LEFT);
    layout.setComponentAlignment(password, Alignment.MIDDLE_LEFT);
    layout.setComponentAlignment(hlayout, Alignment.BOTTOM_LEFT);
    layout.setSpacing(true);
    layout.setMargin(true);

    // Keyboard navigation - enter key is a shortcut to login
    addActionHandler(new Handler() {
        @Override
        public Action[] getActions(Object target, Object sender) {
            return new Action[] { enterKey };
        }

        @Override
        public void handleAction(Action action, Object sender, Object target) {
            tryToLogIn();
        }
    });
}