com.vaadin.data.Validator.InvalidValueException Java Examples

The following examples show how to use com.vaadin.data.Validator.InvalidValueException. 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: NumericQuestion.java    From gazpachoquest with GNU General Public License v3.0 6 votes vote down vote up
public boolean isValid(TextField field, String newValue) {
    boolean valid = true;

    if (StringUtils.isBlank(newValue)) {
        if (field.isRequired()) {
            valid = false;
        }
    } else {
        for (Validator v : field.getValidators()) {
            try {
                v.validate(newValue);
            } catch (InvalidValueException e) {
                valid = false;
                logger.warn(e.getMessage());
                answerField.setComponentError(new UserError(e.getMessage()));
            }
        }
    }
    if (valid) {
        answerField.setComponentError(null);
    }
    return valid;
}
 
Example #2
Source File: ColumnSelectionWindow.java    From XACML with MIT License 6 votes vote down vote up
protected void initializeButton() {
	self.buttonSave.addClickListener(new ClickListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void buttonClick(ClickEvent event) {
			try {
				//
				// Commit
				//
				self.textFieldColumn.commit();
				//
				// If we get here, the value is valid.
				// Mark ourselves as saved and close the window
				//
				self.isSaved = true;
				self.close();
			} catch (SourceException | InvalidValueException e) {
				//
				// Vaadin will display error
				//
			}
		}
	});
}
 
Example #3
Source File: ConfigParamField.java    From XACML with MIT License 6 votes vote down vote up
@Override
public void commit() throws SourceException, InvalidValueException {
	if (this.mainLayout.getComponentCount() == 0) {
		return;
	}
	Component c = this.mainLayout.getComponent(0);
	if (c instanceof SQLPIPConfigurationComponent) {
		((SQLPIPConfigurationComponent)c).commit();
	} else if (c instanceof LDAPPIPConfigurationComponent) {
		((LDAPPIPConfigurationComponent)c).commit();
	} else if (c instanceof CSVPIPConfigurationComponent) {
		((CSVPIPConfigurationComponent)c).commit();
	} else if (c instanceof HyperCSVPIPConfigurationComponent) {
		((HyperCSVPIPConfigurationComponent)c).commit();
	} else if (c instanceof CustomPIPConfigurationComponent) {
		((CustomPIPConfigurationComponent)c).commit();
	}
	super.commit();
}
 
Example #4
Source File: ConfigParamField.java    From XACML with MIT License 6 votes vote down vote up
@Override
public void validate() throws InvalidValueException {
	if (this.mainLayout.getComponentCount() == 0) {
		return;
	}
	Component c = this.mainLayout.getComponent(0);
	if (c instanceof SQLPIPConfigurationComponent) {
		((SQLPIPConfigurationComponent)c).validate();
	} else if (c instanceof LDAPPIPConfigurationComponent) {
		((LDAPPIPConfigurationComponent)c).validate();
	} else if (c instanceof CSVPIPConfigurationComponent) {
		((CSVPIPConfigurationComponent)c).validate();
	} else if (c instanceof HyperCSVPIPConfigurationComponent) {
		((HyperCSVPIPConfigurationComponent)c).validate();
	} else if (c instanceof CustomPIPConfigurationComponent) {
		((CustomPIPConfigurationComponent)c).validate();
	}
	super.validate();
}
 
Example #5
Source File: FunctionSelectionWindow.java    From XACML with MIT License 6 votes vote down vote up
protected void doSave() {
	try {
		//
		// Commit changes
		//
		self.tableFunctions.commit();
		//
		// We are saved
		//
		self.isSaved = true;
		//
		// Close the window
		//
		self.close();
	} catch (SourceException | InvalidValueException e) {
		//
		// Nothing to do, Vaadin highlights
		//
	}
}
 
Example #6
Source File: MatchEditorWindow.java    From XACML with MIT License 6 votes vote down vote up
protected void doSave() {
	try {
		//
		// Commit changes
		//
		self.tableFunctions.commit();
		//
		// We are saved
		//
		self.isSaved = true;
		//
		// Close the window
		//
		self.close();
	} catch (SourceException | InvalidValueException e) {
		return;
	}
}
 
Example #7
Source File: VariableDefinitionEditorWindow.java    From XACML with MIT License 6 votes vote down vote up
protected void initializeButton() {
	this.buttonSave.setClickShortcut(KeyCode.ENTER);
	this.buttonSave.addClickListener(new ClickListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void buttonClick(ClickEvent event) {
			try {
				//
				// Commit it
				//
				self.textFieldID.commit();
				//
				// Save it
				//
				self.variable.setVariableId(self.textFieldID.getValue());
				self.isSaved = true;
				//
				// Close window
				//
				self.close();
			} catch (SourceException | InvalidValueException e) {
			}
		}			
	});
}
 
Example #8
Source File: SubDomainEditorWindow.java    From XACML with MIT License 5 votes vote down vote up
protected void initializeButtons() {
	this.buttonSave.setClickShortcut(KeyCode.ENTER);
	this.buttonSave.setEnabled(false);
	this.buttonSave.addClickListener(new ClickListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void buttonClick(ClickEvent event) {
			try {
				//
				// Make sure the text is valid
				//
				self.textFieldSubdomain.validate();
				//
				// Parse our the subdomain parts
				//
				self.subdomain = self.textFieldSubdomain.getValue();
				self.saved = true;
				//
				// Close it up
				//
				self.close();
			} catch (InvalidValueException e) {
				logger.error(e);
			}
		}
		
	});
}
 
Example #9
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
@SuppressWarnings("serial")
private Validator getMaxValueValidator() {
	return new Validator() {

		@Override
		public void validate(Object value) throws InvalidValueException {
			String v = (String) value;

			// empty is ok
			if (v.isEmpty()) {
				return;
			}

			// integer
			ParameterType t = (ParameterType) type.getValue();
			if (t == ParameterType.INTEGER) {
				// must be integer
				int maxValueInt = getInt(v);

				// if min value exists, must be equal or greater
				isGreaterOrEqualToMinValueInt(maxValueInt);

				// TODO check default after max change
			} 

			
			// DECIMAL
			else if (t == ParameterType.DECIMAL) {
				double maxValueDouble = getDouble(v);
				isGreaterOrEqualToMinValueDouble(maxValueDouble);
			}
		}
	};
}
 
Example #10
Source File: RegexpEditorComponent.java    From XACML with MIT License 5 votes vote down vote up
private void initializeTestPanel() {
	this.textFieldTestValue.setNullRepresentation("");
	
	this.buttonTest.addClickListener(new ClickListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void buttonClick(ClickEvent event) {
			String testValue = self.textFieldTestValue.getValue();
			if (testValue == null || testValue.length() == 0) {
				return;
			}
			String regExp = self.textFieldExpression.getValue();
			if (regExp == null || regExp.length() == 0) {
				return;
			}
			//
			// Create a validator
			//
			Validator validator = new RegexpValidator(regExp, true, "Regular Expression does NOT match.");
			//
			// Add it
			//
			self.textFieldTestValue.addValidator(validator);
			//
			// Validate
			//
			try {
				self.textFieldTestValue.validate();
				AdminNotification.info("Success! Regular Expression Matches");
			} catch (InvalidValueException e) {
				AdminNotification.warn("Failed, Regular Expression does NOT match");
			}
			//
			// Remove the validator
			//
			self.textFieldTestValue.removeValidator(validator);
		}
	});
}
 
Example #11
Source File: CSVPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void validate() throws InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("validate");
	}
	this.textFieldFile.validate();
	this.textFieldDelimiter.validate();
	this.textFieldQuote.validate();
	this.textFieldSkip.validate();
}
 
Example #12
Source File: CSVPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void commit() throws SourceException, InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("commit");
	}
	this.textFieldFile.commit();
	this.textFieldDelimiter.commit();
	this.textFieldQuote.commit();
	
	if (this.textFieldSkip.getValue() == null || this.textFieldSkip.getValue().isEmpty()) {
		this.entity.getEntity().removePipconfigParam((PIPConfigParam) this.textFieldSkip.getData());
		this.textFieldSkip.setData(null);
	}
	this.textFieldSkip.commit();
}
 
Example #13
Source File: SQLPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void validate() throws InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("validate");
	}
	this.comboBoxConnectionType.validate();
	this.textFieldDataSource.validate();
	this.textFieldConnectionURL.validate();
	this.comboBoxSQLDriver.validate();
	this.textFieldPassword.validate();
	this.textFieldUser.validate();
}
 
Example #14
Source File: SQLPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void commit()  throws SourceException, InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("commit");
	}
	this.comboBoxConnectionType.commit();
	
	Object id = this.comboBoxConnectionType.getValue();
	if (id == null) {
		logger.warn("Can't reset combo hasn't selected anything.");
		return;
	}
	if (id.toString().equals(SQL_TYPE_JDBC)) {
		this.textFieldConnectionURL.commit();
		this.comboBoxSQLDriver.commit();
		this.textFieldPassword.commit();
		this.textFieldUser.commit();
		
		this.textFieldDataSource.setData(null);
		this.entity.getEntity().getPipconfigParams().remove(SQL_DATASOURCE);

	} else if (id.toString().equals(SQL_TYPE_JNDI)) {

		this.textFieldDataSource.commit();

		this.textFieldConnectionURL.setData(null);
		this.comboBoxSQLDriver.setData(null);
		this.textFieldPassword.setData(null);
		this.textFieldUser.setData(null);
		/* ???
		this.entity.getEntity().getPipconfigParams().remove(SQL_TYPE);
		this.entity.getEntity().getPipconfigParams().remove(SQL_DRIVER);
		this.entity.getEntity().getPipconfigParams().remove(SQL_URL);
		this.entity.getEntity().getPipconfigParams().remove(SQL_USER);
		this.entity.getEntity().getPipconfigParams().remove(SQL_PASSWORD);
		*/
	}
}
 
Example #15
Source File: LDAPPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void validate() throws InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("validate");
	}
	this.comboBoxAuthentication.validate();
	this.textFieldFactory.validate();
	this.textFieldProviderURL.validate();
	this.textFieldPrincipal.validate();
	this.textFieldCredentials.validate();
	this.textFieldScope.validate();
}
 
Example #16
Source File: LDAPPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void commit() throws SourceException, InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("commit");
	}
	this.comboBoxAuthentication.commit();
	this.textFieldFactory.commit();
	this.textFieldProviderURL.commit();
	this.textFieldPrincipal.commit();
	this.textFieldCredentials.commit();
	this.textFieldScope.commit();
}
 
Example #17
Source File: HyperCSVPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void validate() throws InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("validate");
	}
	this.textFieldSource.validate();
	this.textFieldTarget.validate();
	this.textFieldDefinition.validate();
}
 
Example #18
Source File: HyperCSVPIPConfigurationComponent.java    From XACML with MIT License 5 votes vote down vote up
public void commit() throws SourceException, InvalidValueException {
	if (logger.isDebugEnabled()) {
		logger.debug("commit");
	}
	this.textFieldSource.commit();
	this.textFieldTarget.commit();
	this.textFieldDefinition.commit();
}
 
Example #19
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
/**
 * @throws InvalidValueException if min value exists and i is smaller than min value
 * @param i
 */
private void isGreaterOrEqualToMinValueDouble(double d) {
	if (!minValue.getValue().isEmpty()) {
		try {
			double minValueDouble = Double.parseDouble(minValue.getValue());
			if (d < minValueDouble) {
				throw new InvalidValueException("Smaller than minimum value");
			}
		} catch (NumberFormatException e) {
			// ignore rubbish min value
		}
	}
}
 
Example #20
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
/**
 * @throws InvalidValueException if max value exists and i is greater than max value
 * @param i
 */
private void isSmallerOrEqualToMaxValueInt(int i) {
	if (!maxValue.getValue().isEmpty()) {
		try {
			int maxValueInt = Integer.parseInt(maxValue.getValue());
			if (i > maxValueInt) {
				throw new InvalidValueException("Greater than maximum value");
			}
		} catch (NumberFormatException e) {
			// ignore rubbish max value
		}
	}
}
 
Example #21
Source File: ResolverParamField.java    From XACML with MIT License 5 votes vote down vote up
@Override
public void validate() throws InvalidValueException {
	if (this.mainLayout.getComponentCount() == 0) {
		return;
	}
	Component c = this.mainLayout.getComponent(0);
	if (c instanceof PIPSQLResolverEditorWindow) {
		((PIPSQLResolverEditorWindow)c).validate();
	}
	super.validate();
}
 
Example #22
Source File: ResolverParamField.java    From XACML with MIT License 5 votes vote down vote up
@Override
public void commit() throws SourceException, InvalidValueException {
	if (this.mainLayout.getComponentCount() == 0) {
		return;
	}
	Component c = this.mainLayout.getComponent(0);
	if (c instanceof PIPSQLResolverEditorWindow) {
		((PIPSQLResolverEditorWindow)c).commit();
	}
	super.commit();
}
 
Example #23
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
/**
 * @throws InvalidValueException if min value exists and i is smaller than min value
 * @param i
 */
private void isGreaterOrEqualToMinValueInt(int i) {
	if (!minValue.getValue().isEmpty()) {
		try {
			int minValueInt = Integer.parseInt(minValue.getValue());
			if (i < minValueInt) {
				throw new InvalidValueException("Smaller than minimum value");
			}
		} catch (NumberFormatException e) {
			// ignore rubbish min value
		}
	}
}
 
Example #24
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
@SuppressWarnings("serial")
private Validator getMinValueValidator() {
	return new Validator() {

		@Override
		public void validate(Object value) throws InvalidValueException {
			String v = (String) value;

			// empty is ok
			if (v.isEmpty()) {
				return;
			}

			// integer
			ParameterType t = (ParameterType) type.getValue();
			if (t == ParameterType.INTEGER) {
				// must be integer
				int minValueInt = getInt(v);

				// if min value exists, must be equal or greater
				isSmallerOrEqualToMaxValueInt(minValueInt);
			} 

			
			// DECIMAL
			else if (t == ParameterType.DECIMAL) {
				double minValueDouble = getDouble(v);
				isSmallerOrEqualToMaxValueDouble(minValueDouble);
			}
		}
	};
}
 
Example #25
Source File: Parameter.java    From chipster with MIT License 5 votes vote down vote up
/**
 * @throws InvalidValueException if max value exists and i is greater than max value
 * @param i
 */
private void isSmallerOrEqualToMaxValueDouble(double d) {
	if (!maxValue.getValue().isEmpty()) {
		try {
			double maxValueDouble = Double.parseDouble(maxValue.getValue());
			if (d > maxValueDouble) {
				throw new InvalidValueException("Greater than maximum value");
			}
		} catch (NumberFormatException e) {
			// ignore rubbish max value
		}
	}
}
 
Example #26
Source File: DurationField.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void validate(final Date value) throws InvalidValueException {
    super.validate(value);

    if (value != null && maximumDuration != null && compareTimeOfDates(value, maximumDuration) > 0) {
        throw new InvalidValueException("value is greater than the allowed maximum value");
    }

    if (value != null && minimumDuration != null && compareTimeOfDates(minimumDuration, value) > 0) {
        throw new InvalidValueException("value is smaller than the allowed minimum value");
    }
}
 
Example #27
Source File: ContractApplicationEditViewImplEx.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Override
public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) {
	super.onValidationError(validationErrors);
	StringBuilder sb = new StringBuilder();
	for(Field<?> field: validationErrors.keySet()) {
		if(sb.length()!= 0) {
			sb.append(", ");
		}
		sb.append(field.getCaption());		
	}
	Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE);
}
 
Example #28
Source File: ContractApplicationChangeViewImplEx.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Override
public void onValidationError(Map<Field<?>, InvalidValueException> validationErrors) {
	super.onValidationError(validationErrors);
	StringBuilder sb = new StringBuilder();
	for(Field<?> field: validationErrors.keySet()) {
		if(sb.length()!= 0) {
			sb.append(", ");
		}
		sb.append(field.getCaption());		
	}
	Notification.show("Fehler in folgenden Feldern:", sb.toString(), Notification.Type.ERROR_MESSAGE);
}
 
Example #29
Source File: ContainerDataSource.java    From jdal with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void commit() throws SourceException, InvalidValueException {
	if (!save()) {
		// lost changes?
		discard();
		throw new SourceException(this);
	}
}
 
Example #30
Source File: AttributeSelectionWindow.java    From XACML with MIT License 5 votes vote down vote up
protected void initializeButtons() {
	this.buttonSave.setClickShortcut(KeyCode.ENTER);
	this.buttonSave.addClickListener(new ClickListener() {
		private static final long serialVersionUID = 1L;

		@Override
		public void buttonClick(ClickEvent event) {
			try {
				//
				// Commit everything??
				//
				self.textFieldIssuer.commit();
				self.checkBoxMustBePresent.commit();
				self.currentComponent.commit();
				//
				// Save to the attribute
				//
				String issuer = self.textFieldIssuer.getValue();
				if (issuer == null || issuer.length() == 0) {
					self.attribute.setIssuer(null);
				} else {
					self.attribute.setIssuer(issuer);
				}
				self.attribute.setMustBePresent(self.checkBoxMustBePresent.getValue());
				//
				// Mark as saved
				//
				self.isSaved = true;
				//
				// Close the window
				//
				self.close();
			} catch (SourceException | InvalidValueException e) {
				
			}
		}
	});
}