use of javax.faces.component.visit.VisitContext in project oxTrust by GluuFederation.
the class CustomAttributeAction method validateAttributeValues.
public void validateAttributeValues(ComponentSystemEvent event) {
final FacesContext facesContext = FacesContext.getCurrentInstance();
final List<Object> values = new ArrayList<Object>();
event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof UIInput) {
GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
if (attribute != null) {
values.add(((UIInput) target).getValue());
}
}
return VisitResult.ACCEPT;
}
});
values.removeAll(Arrays.asList(null, ""));
Set<Object> uniqValues = new HashSet<Object>(values);
if (values.size() != uniqValues.size()) {
event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {
@Override
public VisitResult visit(VisitContext context, UIComponent target) {
if (target instanceof UIInput) {
GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
if (attribute != null) {
((UIInput) target).setValid(false);
String message = "Please fill out an unique value for all of '" + attribute.getDisplayName() + "' fields";
facesMessages.add(target.getClientId(facesContext), FacesMessage.SEVERITY_ERROR, message);
}
}
return VisitResult.ACCEPT;
}
});
facesContext.validationFailed();
}
}
Aggregations