This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class EnumLabelsResolver implements LabelResolver { | |
@Override | |
public List<String> resolveLabelsFor(ConstraintDescriptor<?> constraintDescriptor) { | |
List<String> result = new ArrayList<>(); | |
for (Method annotationMethod : constraintDescriptor.getAnnotation().annotationType().getDeclaredMethods()) { | |
if (LabelId.class.isAssignableFrom(annotationMethod.getReturnType())) { | |
try { | |
LabelId labelId = (LabelId) annotationMethod.invoke(constraintDescriptor.getAnnotation()); | |
result.add(labelId.getId()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ApplicationScoped | |
public class DbMessageSourceAdapter implements MessageSourceAdapter { | |
@Inject | |
private ViolationMessageDao violationMessageDao; | |
@Override | |
public String resolveMessage(String key, Locale locale) { | |
return violationMessageDao.findByKey(key); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.os890.bv.addon</groupId> | |
<artifactId>cdi-bv-label-addon</artifactId> | |
<version>1.0.0</version> | |
</dependency> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Person { | |
@Length(min = 1, max = 50, messageId = MY_LENGTH_MSG, propertyLabel = FIRST_NAME) | |
private String fName; | |
@Length(min = 2, max = 50, messageId = MY_LENGTH_MSG, propertyLabel = LAST_NAME) | |
private String lName; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum MyLabel implements LabelId { | |
FIRST_NAME("firstName"), LAST_NAME("lastName"); | |
private final String key; | |
MyLabel(String key) { | |
this.key = "{" + key + "}"; | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ReportAsSingleViolation | |
@Size | |
@Constraint(validatedBy = {}) | |
@Target({FIELD, METHOD, PARAMETER}) | |
@Retention(RUNTIME) | |
public @interface Length { | |
String message() default "{}"; //triggers the delegation to #messageId | |
Class<?>[] groups() default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MessageId { | |
String getId(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ProfileA | |
//further cdi-annotation/s | |
public class BeanProfileA { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Profile("X") | |
//further cdi annotation/s | |
public class BeanProfileX { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultiProfileExtension implements Extension { | |
private Set<String> activeProfileNames = new HashSet<>(); | |
protected void determineActiveProfiles(@Observes BeforeBeanDiscovery beforeBeanDiscovery) { | |
String activeProfileString = | |
ConfigResolver.getPropertyValue("active-profiles", "Production"); | |
Collections.addAll(activeProfileNames, activeProfileString.split(",")); | |
} | |
protected void matchActiveProfiles(@Observes ProcessAnnotatedType pat, BeanManager bm) { |
NewerOlder