Validar duplicados en un autocomplete multiple
Para validar duplicados en un autocomplete múltiple usamos
public List<Rol> completeFiltrado(String query) {
List<Rol> suggestions = new ArrayList<>();
List<Rol> temp = new ArrayList<>();
try {
Boolean found = false;
query = query.trim();
String field = (String) UIComponent.getCurrentComponent(FacesContext.getCurrentInstance()).getAttributes().get("field");
temp = rolRepository.findRegex(field, query, true, new Document(field, 1));
if (rolList.isEmpty()) {
if (!temp.isEmpty()) {
suggestions = temp;
}
} else {
if (!temp.isEmpty()) {
for (Rol r : temp) {
found = false;
for (Rol r2 : rolList) {
if (r.getIdrol().equals(r2.getIdrol())) {
found = true;
}
}
if (!found) {
suggestions.add(r);
}
}
}
}
//suggestions= rolRepository.findRegex(field,query,true,new Document(field,1));
} catch (Exception e) {
errorServices.errorMessage(nameOfClass(), nameOfMethod(), e.getLocalizedMessage());
}
return suggestions;
}
Last updated
Was this helpful?