本文整理匯總了Java中javax.validation.ConstraintValidatorContext.disableDefaultConstraintViolation方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstraintValidatorContext.disableDefaultConstraintViolation方法的具體用法?Java ConstraintValidatorContext.disableDefaultConstraintViolation怎麽用?Java ConstraintValidatorContext.disableDefaultConstraintViolation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.validation.ConstraintValidatorContext
的用法示例。
在下文中一共展示了ConstraintValidatorContext.disableDefaultConstraintViolation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: validateInterestDate
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
private boolean validateInterestDate(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
InterestDate interestDate = (InterestDate) fieldObj.get(validateThis);
Interest interest = (Interest) dependentFieldObj.get(validateThis);
if (interest != null && !interestTypeIsNoInterest(interest.getType())) {
Set<ConstraintViolation<Object>> violations = validator.validate(interestDate);
if (!violations.isEmpty()) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate(getViolationMessages(violations, ctx))
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
}
return true;
}
示例2: validateRate
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
private boolean validateRate(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
BigDecimal rate = (BigDecimal) fieldObj.get(validateThis);
Interest.InterestType type = (Interest.InterestType) dependentFieldObj.get(validateThis);
if ((type == null || !interestTypeIsNoInterest(type)) && rate == null) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate("may not be null")
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
return true;
}
示例3: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(final String password, final ConstraintValidatorContext context) {
final PasswordValidator validator = new PasswordValidator(singletonList(
new LengthRule(8, 30)
// More rules can be added to increase security
));
final RuleResult result = validator.validate(new PasswordData(password));
if (result.isValid()) {
return true;
}
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(
validator.getMessages(result).stream().collect(joining("\n"))
).addConstraintViolation();
return false;
}
示例4: validateReason
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
private boolean validateReason(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
String reason = (String) fieldObj.get(validateThis);
InterestDate.InterestDateType type = getInterestDateType(validateThis, dependentFieldObj);
if ((type == null || !interestDateTypeIsSubmission(type)) && isBlank(reason)) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate("may not be empty")
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
return true;
}
示例5: validateInputDate
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
private boolean validateInputDate(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
LocalDate inputDate = (LocalDate) fieldObj.get(validateThis);
InterestDate.InterestDateType type = getInterestDateType(validateThis, dependentFieldObj);
if (type == null || !interestDateTypeIsSubmission(type)) {
Set<ConstraintViolation<Object>> violations
= Optional.ofNullable(inputDate).isPresent() ? validator.validate(inputDate) : Collections.emptySet();
if (!violations.isEmpty()) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate(getViolationMessages(violations, ctx))
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
}
return true;
}
示例6: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if(value == null) {
return false;
}
check = new SafeguardCheck();
parametros.forEach((parametro) -> check.elementOf(value, parametro).validate());
if(check.hasError()) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("(" + value + ") contém caracteres inválidos ")
.addConstraintViolation();
}
return !check.hasError();
}
示例7: createViolationMessageForNestedProperty
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
static void createViolationMessageForNestedProperty(final String nestedProperty, final String messageTemplate, final
ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
String[] splitted = nestedProperty.split("\\.");
ConstraintValidatorContext.ConstraintViolationBuilder builder = context.buildConstraintViolationWithTemplate(messageTemplate);
ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderDefinedContext nodeDefinedContext = null;
ConstraintValidatorContext.ConstraintViolationBuilder.NodeBuilderCustomizableContext nodeCustomizableContext = null;
for (String s : splitted) {
if (nodeDefinedContext == null) {
nodeDefinedContext = builder.addNode(s);
} else if (nodeCustomizableContext == null) {
nodeCustomizableContext = nodeDefinedContext.addNode(s);
} else {
nodeCustomizableContext = nodeCustomizableContext.addNode(s);
}
}
if (nodeDefinedContext == null) {
builder.addConstraintViolation();
} else if (nodeCustomizableContext == null) {
nodeDefinedContext.addConstraintViolation();
} else {
nodeCustomizableContext.addConstraintViolation();
}
}
示例8: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
/**
* Validating, that a given password is secure.
* A secure password has a length between 8 and 30 characters, a minimum of one uppercase, one lowercase, one digit
* and one special letter. There is also no wihtespace inside the string.
*
* @param password password that have to be proofed in order tob be a secure one.
* @param context a simple ConstraintValidatorContext.
* @return true, if the given password is secure.
*/
@Override
public boolean isValid(String password, ConstraintValidatorContext context) {
final PasswordValidator validator = new PasswordValidator(Arrays.asList(
new LengthRule(8, 30),
new CharacterRule(EnglishCharacterData.UpperCase, 1),
new CharacterRule(EnglishCharacterData.LowerCase, 1),
new CharacterRule(EnglishCharacterData.Digit, 1),
new CharacterRule(EnglishCharacterData.Special, 1),
new WhitespaceRule()));
final RuleResult result = validator.validate(new PasswordData(password));
final boolean resultIsValid;
if (result.isValid())
resultIsValid = true;
else {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(Joiner.on(",").join(validator.getMessages(result)))
.addConstraintViolation();
resultIsValid = false;
}
return resultIsValid;
}
示例9: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
context.disableDefaultConstraintViolation();
try {
String password = (String) ValidatorUtil.getFieldValue(value, passwordFieldName);
String passwordVerification = (String) ValidatorUtil.getFieldValue(value, passwordVerificationFieldName);
if (passwordsAreNotEqual(password, passwordVerification)) {
ValidatorUtil.addValidationError(passwordFieldName, context);
ValidatorUtil.addValidationError(passwordVerificationFieldName, context);
return false;
}
}
catch (Exception ex) {
throw new RuntimeException("Exception occurred during validation", ex);
}
return true;
}
示例10: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(List<String> values, ConstraintValidatorContext context) {
if(values == null || values.isEmpty()) {
return true;
}
for (String val : values) {
boolean valid = false;
for(String cat: categories) {
if(cat.equals(val)) {
valid = true;
}
}
if(!valid) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
return false;
}
}
return true;
}
示例11: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
try {
final String fieldValue = BeanUtils.getProperty(value, fieldName);
final String notNullFieldValue = BeanUtils.getProperty(value, notNullFieldName);
if (StringUtils.equals(fieldValue, fieldSetValue) && StringUtils.isEmpty(notNullFieldValue)) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
.addPropertyNode(notNullFieldName).addConstraintViolation();
return false;
}
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
return true;
}
示例12: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
public boolean isValid(String value, ConstraintValidatorContext constraintContext) {
if (value != null) {
UserPage page = (UserPage) WicketUtils.getPage();
AuthenticationToken token = new UsernamePasswordToken(page.getUser().getName(), value);
try {
if (SecurityUtils.getSecurityManager().authenticate(token) != null)
return true;
} catch (Exception e) {
}
constraintContext.disableDefaultConstraintViolation();
constraintContext.buildConstraintViolationWithTemplate("Current password does not match").addConstraintViolation();
return false;
} else {
return true;
}
}
示例13: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(Object[] value, ConstraintValidatorContext context) {
Set<String> expectedParams = new HashSet<>();
for (Annotation[] annotations: resourceInfo.getResourceMethod().getParameterAnnotations()) {
for (Annotation annotation: annotations) {
if (annotation instanceof QueryParam) {
QueryParam param = (QueryParam) annotation;
expectedParams.add(param.value());
}
}
}
Set<String> actualParams = new HashSet<>(uriInfo.getQueryParameters().keySet());
actualParams.removeAll(expectedParams);
if (actualParams.isEmpty()) {
return true;
} else {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("Unexpected query params: " + actualParams).addConstraintViolation();
return false;
}
}
示例14: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(Map<String, String> map, ConstraintValidatorContext context)
{
for (String key : map.keySet())
{
if (key == null || key.isEmpty())
{
context.disableDefaultConstraintViolation(); // disable violation message
context.buildConstraintViolationWithTemplate("key value cannot be null or empty").addConstraintViolation(); // add message
return false;
}
if (map.get(key) == null || map.get(key).isEmpty())
{
context.disableDefaultConstraintViolation(); // disable violation message
context.buildConstraintViolationWithTemplate("value cannot be null or empty for key: " + key).addConstraintViolation(); // add message
return false;
}
}
return true;
}
示例15: isValid
import javax.validation.ConstraintValidatorContext; //導入方法依賴的package包/類
@Override
public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final PropertyAccessor bean = new BeanWrapperImpl(value);
final String propertyValue = String.valueOf(bean.getPropertyValue(property));
@SuppressWarnings({"rawtypes", "unchecked"})
final Class<WithId> modelClass = (Class) value.getKind().modelClass;
@SuppressWarnings("unchecked")
final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);
final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);
if (!isUnique) {
if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) {
return true;
}
context.disableDefaultConstraintViolation();
context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue)
.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
.addPropertyNode(property).addConstraintViolation();
}
return isUnique;
}