List of usage examples for org.springframework.beans BeanWrapper getPropertyValue
@Nullable
Object getPropertyValue(String propertyName) throws BeansException;
From source file:com.example.session.app.validation.ConfirmValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); Object fieldValue = beanWrapper.getPropertyValue(field); Object confirmFieldValue = beanWrapper.getPropertyValue(confirmField); boolean matched = ObjectUtils.nullSafeEquals(fieldValue, confirmFieldValue); if (matched) { return true; } else {/*from www . jav a2 s .c o m*/ context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addPropertyNode(field).addConstraintViolation(); return false; } }
From source file:com.kazuki43zoo.jpetstore.component.validation.RepeatedFieldValidator.java
public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); Object fieldValue = beanWrapper.getPropertyValue(field); Object repeatedFieldValue = beanWrapper.getPropertyValue(repeatedField); boolean matched = Objects.equals(fieldValue, repeatedFieldValue); if (matched) { return true; } else {//from ww w.j a va 2 s . com context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addPropertyNode(repeatedField) .addConstraintViolation(); return false; } }
From source file:com.indusborn.ui.validators.ConfirmValidator.java
public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); Object fieldValue = beanWrapper.getPropertyValue(field); Object matchesValue = beanWrapper.getPropertyValue(matches); boolean matched = ObjectUtils.nullSafeEquals(fieldValue, matchesValue); if (matched) { return true; } else {//from w ww . j a v a 2 s . co m context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(message).addNode(field).addConstraintViolation(); return false; } }
From source file:com.oreilly.springdata.neo4j.CollectionPathMatcher.java
@Override protected boolean matchesSafely(Collection<Object> item) { for (Object outer : item) { BeanWrapper wrapper = new BeanWrapperImpl(outer); Object property = wrapper.getPropertyValue(collectionPath); if (propertyMatcher.matches(property)) { return true; }/*from w w w . j a va 2 s.c om*/ } return false; }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * Retrieves a PropertyDescriptor for the specified instance and property value * * @param instance The instance/*w w w . j a v a2 s . com*/ * @param propertyValue The value of the property * @return The PropertyDescriptor */ public static PropertyDescriptor getPropertyDescriptorForValue(Object instance, Object propertyValue) { if (instance == null || propertyValue == null) return null; BeanWrapper wrapper = new BeanWrapperImpl(instance); PropertyDescriptor[] descriptors = wrapper.getPropertyDescriptors(); for (int i = 0; i < descriptors.length; i++) { Object value = wrapper.getPropertyValue(descriptors[i].getName()); if (propertyValue.equals(value)) return descriptors[i]; } return null; }
From source file:org.obiba.magma.beans.BeanPropertyVariableValueSource.java
@Nullable protected Object getPropertyValue(String propertyPath, BeanWrapper bw) { try {/*from w w w . j a v a 2 s. c om*/ return bw.getPropertyValue(propertyPath); } catch (NullValueInNestedPathException e) { return null; } catch (InvalidPropertyException e) { throw new MagmaRuntimeException("Invalid definition of variable " + getVariable().getName() + ". Cannot obtain value for property '" + e.getPropertyName() + "' on bean of class " + e.getBeanClass(), e); } }
From source file:com.github.ukase.web.validation.RequiredAnyOfValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); for (String field : fields) { Object v = beanWrapper.getPropertyValue(field); if (v != null) { return true; }//from w w w. jav a 2 s .com } return false; }
From source file:com.example.securelogin.app.common.validation.OldPasswordValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); String username = (String) beanWrapper.getPropertyValue(usernamePropertyName); String oldPassword = (String) beanWrapper.getPropertyValue(oldPasswordPropertyName); Account account = accountSharedService.findOne(username); String currentPassword = account.getPassword(); return checkOldPasswordMacheWithCurrentPassword(oldPassword, currentPassword, context); }
From source file:com.example.securelogin.app.common.validation.StrongPasswordValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); String username = (String) beanWrapper.getPropertyValue(usernamePropertyName); String newPassword = (String) beanWrapper.getPropertyValue(newPasswordPropertyName); RuleResult result = characteristicPasswordValidator .validate(PasswordData.newInstance(newPassword, username, null)); if (result.isValid()) { return true; } else {/* w w w.j a v a2s. co m*/ context.disableDefaultConstraintViolation(); for (String message : characteristicPasswordValidator.getMessages(result)) { context.buildConstraintViolationWithTemplate(message).addPropertyNode(newPasswordPropertyName) .addConstraintViolation(); } return false; } }
From source file:cz.clovekvtisni.coordinator.server.validation.constraints.impl.ComparePropertiesValidator.java
@SuppressWarnings("unchecked") @Override/* w w w . j a va 2 s . co m*/ public boolean isValid(Object bean, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(bean); Object value1 = beanWrapper.getPropertyValue(annotation.firstProperty()); Object value2 = beanWrapper.getPropertyValue(annotation.secondProperty()); boolean valid; switch (annotation.operator()) { case NOT_EQ: valid = (value1 == null && value2 != null || value1 != null && !value1.equals(value2)); break; case EQ: valid = (value1 == null && value2 == null || value1 != null && value1.equals(value2)); break; case LT: valid = value1 == null || value2 == null || ((Comparable) value1).compareTo(value2) < 0; break; case LE: valid = value1 == null || value2 == null || ((Comparable) value1).compareTo(value2) <= 0; break; case GT: valid = value1 == null || value2 == null || ((Comparable) value1).compareTo(value2) > 0; break; case GE: valid = value1 == null || value2 == null || ((Comparable) value1).compareTo(value2) >= 0; break; default: throw new IllegalStateException("unsupported operator " + annotation.operator()); } if (!valid) { context.buildConstraintViolationWithTemplate(annotation.message()).addNode(annotation.firstProperty()) .addConstraintViolation().disableDefaultConstraintViolation(); } return valid; }