Java Code Examples for com.vaadin.ui.Field#addValidator()

The following examples show how to use com.vaadin.ui.Field#addValidator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServerConfigForm.java    From sensorhub with Mozilla Public License 2.0 6 votes vote down vote up
@Override
protected Field<?> buildAndBindField(String label, String propId, Property<?> prop)
{
    Field<?> field = super.buildAndBindField(label, propId, prop);
    
    if (propId.equals(PROP_SERVLET_ROOT))
    {
        field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 2, 256, false));
    }
    else if (propId.equals(PROP_HTTP_PORT))
    {
        field.setWidth(100, Unit.PIXELS);
        //((TextField)field).getConverter().
        field.addValidator(new Validator() {
            private static final long serialVersionUID = 1L;
            public void validate(Object value) throws InvalidValueException
            {
                int portNum = (Integer)value;
                if (portNum > 10000 || portNum <= 80)
                    throw new InvalidValueException("Port number must be an integer number greater than 80 and lower than 10000");
            }
        });
    }
    
    return field;
}
 
Example 2
Source File: GenericStorageConfigForm.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
protected Field<?> buildAndBindField(String label, String propId, Property<?> prop)
{
    Field<Object> field = (Field<Object>)super.buildAndBindField(label, propId, prop);
    
    if (propId.equals(PROP_STORAGE_PATH))
        field.setVisible(false);
    
    else if (propId.equals(PROP_DATASRC_ID))
    {
        field = makeModuleSelectField(field, IDataProducerModule.class);
        field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false));
    }
    
    return field;
}
 
Example 3
Source File: SOSConfigForm.java    From sensorhub with Mozilla Public License 2.0 5 votes vote down vote up
protected Field<?> buildAndBindField(String label, String propId, Property<?> prop)
{
    Field<Object> field = (Field<Object>)super.buildAndBindField(label, propId, prop);
    
    if (propId.endsWith(PROP_ENDPOINT))
    {
        field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false));
    }
    else if (propId.endsWith(PROP_ENABLED))
    {
        field.setVisible(true);
    }
    else if (propId.endsWith(PROP_URI))
    {
        field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false));
    }
    else if (propId.endsWith(PROP_STORAGEID))
    {
        field = makeModuleSelectField(field, IStorageModule.class);
    }
    else if (propId.endsWith(PROP_SENSORID))
    {
        field = makeModuleSelectField(field, ISensorModule.class);
        field.addValidator(new StringLengthValidator(MSG_REQUIRED_FIELD, 1, 256, false));
    }
    else if (propId.endsWith(PROP_DATAPROVIDERS + PROP_SEP + PROP_NAME))
        field.setVisible(true);
    
    return field;
}