# filterBetweenDatePaginationWithoutHour()Buscar en rangos de fechas excluyendo la hora con paginacion

## Buscar en rangos de fechas excluyendo la hora con paginaciòn

* A veces necesitamos filtrar datos en rangos de fechas excluyendo la hora.
* En este ejemplo almacenamos en atributos de tipo Date fecha/hora, si hacemos un filtro normal va a excluir en base a la hora y queremos omitir las horas.
* ![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X847w7-641AXqR4F%2Ffechahora.png?generation=1554820666662892\&alt=media)

Mostrar todos los registros

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X849f3s1qQcnRaKn%2Ffiltar.png?generation=1554820667070769\&alt=media)

Aplicamos el componente para realizar el filtro

```java
 <b:row>
    <b:column medium-screen="25" >

         <a:searchBetweenDate
                 renderedMove="true"
                 labelDesde="#{msg['field.fechainicio']}"
                 valueDesde="#{viajeController.lookupServices.fechaDesde}"
                 labelHasta="#{msg['field.fechafin']}"
                 valueHasta="#{viajeController.lookupServices.fechaHasta}"
                 renderedList="#{applicationMenu.viaje.list}"
                 search="#{viajeController.searchBy('_betweendates')}"
           />
       </b:column>
     </b:row>
```

## Al aplicar el filtro

* Se observa que devuelve los registros en esas fechas excluyendo las horas
* Internamente en el repository se asigna la hora de inicio en 0:0 y la hora final en 23:59
* ![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X84BJL9DWnn28YeF%2Ffiltro18.png?generation=1554820666738947\&alt=media)
* **LookupServices**

Agregar

* Date fechaDesde
* Date fechaHasta

```java
   private Date fechaDesde;
   private Date fechaHasta;
```

### En el Controller

#### searchBy()

* Asignamos el parámetro de búsqueda desde el componente en el formulario
* Implementar el filtro

```java
viajeList = viajeRepository.filterBetweenDatePaginationWithoutHours("activo", "si", "fechahorainicioreserva", lookupServices.getFechaDesde(), "fechahorafinreserva", lookupServices.getFechaHasta(), page, rowPage, new Document("idviaje", -1));
```

```java
public String searchBy(String string) {
        try {

            loginController.put("searchviaje", string);

            writable = true;
            move();

        } catch (Exception e) {
            errorServices.errorMessage(nameOfClass(), nameOfMethod(), e.getLocalizedMessage());
        }
        return "";
    }
```

move()

```java
public void move() {

        try {

            Document doc;
            Document sort = new Document("idviaje", -1);

            switch (loginController.get("searchviaje")) {
                case "_init":
                case "_autocomplete":
                    viajeList = viajeRepository.findPagination(page, rowPage, sort);
                    break;

                case "idviaje":
                    if (lookupServices.getIdviaje() != null) {
                        viajeList = viajeRepository.findPagination(new Document("idviaje", lookupServices.getIdviaje()), page, rowPage, new Document("idviaje", -1));
                    } else {
                        viajeList = viajeRepository.findPagination(page, rowPage, sort);
                    }

                    break;

                case "_betweendates":
                    viajeList = viajeRepository.filterBetweenDatePaginationWithoutHours("activo", "si", "fechahorainicioreserva", lookupServices.getFechaDesde(), "fechahorafinreserva", lookupServices.getFechaHasta(), page, rowPage, new Document("idviaje", -1));
                    break;
                default:

                    viajeList = viajeRepository.findPagination(page, rowPage, sort);
                    break;
            }

            viajeFiltered = viajeList;

            viajeDataModel = new ViajeDataModel(viajeList);

        } catch (Exception e) {
            errorServices.errorMessage(nameOfClass(), nameOfMethod(), e.getLocalizedMessage());
        }
    }
```

### Componente searchBetweenDate

Java Server Faces nos permite personalizar los componentes

```java
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:p="http://primefaces.org/ui"
      xmlns:composite="http://java.sun.com/jsf/composite"
      xmlns:b="http://bootsfaces.net/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <composite:interface >

        <composite:attribute name="update" default =":form:dataTable" />

        <composite:attribute name="labelDesde" />
        <composite:attribute name="valueDesde" />
         <composite:attribute name="labelHasta" />
         <composite:attribute name="valueHasta" />
         <composite:attribute name="colSpans" default="2,3,2,3,2"/>
         <composite:attribute name="renderedMove" default="true" />
        <composite:attribute name="pattern" default ="dd/MM/yyy"/>
        <composite:attribute name="columns" default="3" />
        <composite:attribute name="renderedList" />

        <composite:attribute name="search"  
                             method-signature="java.lang.String action()" />


    </composite:interface>
    <composite:implementation>
            <p:remoteCommand name="remotesearch"
                             update="#{cc.attrs.update}"/>

            <b:panelGrid  columns="#{cc.attrs.columns}" size="xs" colSpans="#{cc.attrs.colSpans}"> 
                <p:outputLabel value="#{cc.attrs.labelDesde}"/>
                <p:calendar
                    value="#{cc.attrs.valueDesde}"
                    required="false" 
                    pattern="#{cc.attrs.pattern}"
                    selectOtherMonths="true"
                    navigator="true"
                    />
                 <p:outputLabel value="#{cc.attrs.labelHasta}"/>
                <p:calendar
                    value="#{cc.attrs.valueHasta}"
                    required="false" 
                    pattern="#{cc.attrs.pattern}"
                    selectOtherMonths="true"
                    navigator="true"
                    />
                <b:commandButton update="#{cc.attrs.update}"
                                 look="info"
                                 oncomplete="remotesearch()"
                                 iconAwesome="fa-filter" 
                                 rendered="#{cc.attrs.renderedList}" 
                                 title="#{app['button.search']}" 
                                 action="#{cc.attrs.search}"/>
            </b:panelGrid>
        <!--</b:panel>-->
    </composite:implementation>
</html>
```
