AutoComplete findRegex() Expresiones Regulares
Desarrollaremos un ejemplo sencillo de una autocomplete utilzando expresiones regulares para busquedas en una coleccion en MongoDB, utilizando ejbmoordb.
Libro sobre jmoordb
https://www.gitbook.com/book/avbravo/jmoordb/details
Crear el Services
Desarrollaremos un ejemplo sencillo de una autocomplete utilzando expresiones regulares para busquedas en una coleccion en MongoDB, utilizando ejbmoordb.
Libro sobre jmoordb
https://www.gitbook.com/book/avbravo/jmoordb/details
Crear el Services
exit: Ctrl + ↩
@Stateless
public class AulasServices {
@Inject
AulasFacade aulasFacade;
public static LocalTime getHour(){
return LocalTime.now();
}
public List<Aulas> complete(String query) {
List<Aulas> suggestions = new ArrayList<>();
try {
query = query.trim();
if (query.length() < 1) {
return suggestions;
}
suggestions = aulasFacade.findRegex("idaula", query,true,new Document("idaula",1));
} catch (Exception e) {
JsfUtil.addErrorMessage("complete() " + e.getLocalizedMessage());
}
return suggestions;
}
}
En el Controller
exit: Ctrl + ↩
@Inject
AulasServices aulasServices;
Aulas aulasSelected;
public AulasServices getAulasServices() {
return aulasServices;
}
public void setAulasServices(AulasServices aulasServices) {
this.aulasServices = aulasServices;
}
public Aulas getAulasSelected() {
return aulasSelected;
}
public void setAulasSelected(Aulas aulasSelected) {
this.aulasSelected = aulasSelected;
}
@Override
public void handleSelect(SelectEvent event) {
try {
aulasList.removeAll(aulasList);
aulasList.add(aulasSelected);
aulasFiltered = aulasList;
aulasDataModel = new AulasDataModel(aulasList);
} catch (Exception ex) {
JsfUtil.addErrorMessage("handleSelect() " + ex.getLocalizedMessage());
}
}
En la pƔgina xhtml
<div class="form-group row">
<p:outputLabel class="col-xs-2 col-form-label" value="#{msg['info.by']} #{msg.idaula}"/>
<div class="col-xs-4">
<p:autoComplete scrollHeight="250" dropdown="false" size="45" emptyMessage="#{msg['info.nohayregistros']}"
title="#{msg['info.by']} #{msg.idaula}"
label="#{msg['info.by']} #{msg.idaula}"
alt="#{msg['info.searchby']} #{msg.idaula}"
value="#{aulasController.aulasSelected}"
completeMethod="#{aulasController.aulasServices.complete}"
var="p" itemLabel="#{p.idaula}" itemValue="#{p}" forceSelection="true">
<f:converter binding="#{aulasConverter}"/>
<p:ajax event="itemSelect" listener="#{aulasController.handleSelect}" update=" :form:msgs,:form:dataTable" />
<f:facet name="itemtip">
<h:panelGrid columns="1" cellpadding="5">
<h:outputText value="#{p.idaula}" />
<h:outputText value="#{p.maximo}" />
</h:panelGrid>
</f:facet>
</p:autoComplete>
</div>
Resultado
Comments