Grails: How do I get my page to load a filter when the page loads?

In index.gsp, I have this to redirect it to list.gsp, so I imagine there should be something like this:

${response.sendRedirect("entry/list")}

My filter is just one textField and two datePickers with drop-down lists (DD-MMM-YYYY) and they should be filtered by default from today to infinity. Therefore, he should show me only those events that have not yet occurred, but the old ones should still be in the database.

Here are links to my last 3 questions for reference.

I have a bunch of data and I need a data filter using Grails

Grails: filter data in a Grails table dynamically

Grails: edit and delete links do not work

I think the second is the one who has most of my code.

Any help would be greatly appreciated. Thank you! :) And once again, special thanks to proflux for all the help!

UPDATE

Here is the list on the .gsp list

<g:each in="${entryInstanceList}" status="i" var="entryInstance">
                    <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        <td><g:formatDate format="dd-MMMM-yyyy" date="${entryInstance.fechaCambio}" /></td>
                        <td><b>${fieldValue(bean: entryInstance, field: 'proyectoRuta')}</b></td>
                        <td>${fieldValue(bean: entryInstance, field: 'summary')}</td>
                        <td><g:formatDate format="dd-MMM-yyyy HH:mm z" date="${entryInstance.lastUpdated}" /></td>
                        <td>
                        <g:form>
                            <g:hiddenField name="id" value="${entryInstance?.id}" />
                            <span class="simple"><g:actionSubmit class="editar" action="edit" value="${message(code: 'default.button.editar.label', default: '&nbsp;&nbsp;&nbsp;')}" /></span>
                            <span class="simple"><g:actionSubmit class="eliminar" action="delete" value="${message(code: 'default.button.eliminar.label', default: '&nbsp;&nbsp;&nbsp;')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Esta seguro que desea Eliminar?')}');" /></span>
                        </g:form>
                        </td>
                    </tr>
</g:each>

UPDATE

Here is the searchResults code,

def searchResults = { 
    def entryCriteria = Entry.createCriteria()

    def results = entryCriteria.list {
        and{if(params?.fechaCambioD && params?.fechaCambioH) { 
            between("fechaCambio", params.fechaCambioD, params.fechaCambioH) 
            } 

        if(params?.lastUpdatedD && params?.lastUpdatedH) { 
            between("lastUpdated", params.lastUpdatedD, params.lastUpdatedH) 
            }

        if(params?.proyectoRutaN) { 
            ilike("proyectoRuta","%${params.proyectoRutaN}%")
            }            
        }
        }
        render(view:'searchResults', model:['results':results, 'proyectoRutaN':params?.proyectoRutaN, 'fechaCambioD':params?.fechaCambioD, 'fechaCambioH':params?.fechaCambioH, 'lastUpdatedD':'', 'lastUpdatedH':params?.lastUpdatedH]) 
}

And since I already use the results and the list, what should I do, give it a different name and in the end put it on the model after the results? as:

render(view:'searchResults', model:['results':results, 'otherResults':otherResults, 'proyectoRutaN':params?.proyectoRutaN, 'fechaCambioD':params?.fechaCambioD, 'fechaCambioH':params?.fechaCambioH, 'lastUpdatedD':'', 'lastUpdatedH':params?.lastUpdatedH])

Or do I just need to define it inside the results?

UPDATE

<table><tbody class="yui-skin-sam">
<tr class="prop">
    <td valign="top" class="name"><b>Proyecto/Ruta: </b> &nbsp;&nbsp;&nbsp;<g:textField name="proyectoRutaN" value="${proyectoRutaN}" /></td>
    <td></td>
    <td valign="top" class="name"><b>Fecha de Implementación: </b></td>
    <td></td>
    <td valign="top" class="name"><b>Fecha de Última Modificación: </b></td>
</tr>
<tr class="prop">
    <td></td>
    <td valign="top">Desde:</td>
    <td valign="top"><gui:datePicker name="fechaCambioD" value="${params?.fechaCambioD}"  formatString="dd/MMM/yyyy"/></td>
    <td valign="top">Desde:</td>
    <td valign="top"><gui:datePicker name="lastUpdatedD" value="${params?.lastUpdatedD}" default="none"/></td>
</tr>
<tr class="prop">
    <td></td>
    <td valign="top">Hasta:</td>
    <td valign="top"><gui:datePicker name="fechaCambioH" value="${params?.fechaCambioH}"  formatString="dd/MMM/yyyy"/></td>
    <td valign="top">Hasta:</td>
    <td valign="top"><gui:datePicker name="lastUpdatedH" value="${params?.lastUpdatedH}" default="none"/></td>
</tr>

For some reason, when I apply filters, it shows me everything in the list (it does not filter), and the text fields in the filter do not save the date from the moment the filter was applied.

Any ideas on how I can fix this?

0
source share
2 answers

, GSP, , , - :

def index {
  redirect(action:'list')
}

, , GSP .

, . , . , :

  • fechaCambioD fechaCambioH
  • fechaCambioD fechaCambioH ( - )

, fechaCambioH

, :

def fechaCambioD = params?.fechaCambioD ?: new Date()

def results = entryCriteria.list {
    if(params?.fechaCambioD && params?.fechaCambioH) { 
        between("fechaCambio", params.fechaCambioD, params.fechaCambioH) 
    } 
    else {
      gte("fechaCambio", fechaComabioD)
    }

    if(params?.lastUpdatedD && params?.lastUpdatedH) { 
        between("lastUpdated", params.lastUpdatedD, params.lastUpdatedH) 
        }

    if(params?.proyectoRutaN) { 
        ilike("proyectoRuta","%${params.proyectoRutaN}%")
        }            
    }

, :

  • fechaCambioD, fechaCambioD.
  • fechaCambioD fechaCambioH, , fechaCambio , .

, , ...

UPDATE:

, , gte comaparator, ge gt . , :

def list = {
   def today = Calendar.getInstance()
   today.set(Calendar.HOUR, 0)
   today.set(Calendar.MINUTE, 0)
   today.set(Calendar.SECOND, 0)
   today.set(Calendar.MILLISECOND, 0)
   def results = Entry.findAllByFechaCambioGreaterThanEquals(today.getTime()) 
   render(view:'list', model:['entryInstanceList':results])
}

, ...

0

fechaCambio - :

def searchResults = { 
    def fromCal
    if(params?.fechaCambioD) {
      fromCal = Calendar.getInstance()
      fromCal.setTime(param?.fechaCambioD)
      fromCal.set(Calendar.HOUR_OF_DAY,0)
      fromCal.set(Calendar.MINUTE,0)
      fromCal.set(Calendar.SECOND,0)
      fromCal.set(Calendar.MILLISECOND,0)
    }
    def toCal
    if(params?.fechaCambioH) {

      toCal = Calendar.getInstance()
      toCal.setTime(param?.fechaCambioH)
      toCal.set(Calendar.HOUR_OF_DAY,23)
      toCal.set(Calendar.MINUTE,59)
      toCal.set(Calendar.SECOND,59)
      toCal.set(Calendar.MILLISECOND,999)
    }
    def entryCriteria = Entry.createCriteria()

    def results = entryCriteria.list {
        and{if(params?.fechaCambioD && params?.fechaCambioH) { 
            between("fechaCambio", fromCal.getTime(), toCal.getTime()) 
            } 

        if(params?.lastUpdatedD && params?.lastUpdatedH) { 
            between("lastUpdated", params.lastUpdatedD, params.lastUpdatedH) 
            }

        if(params?.proyectoRutaN) { 
            ilike("proyectoRuta","%${params.proyectoRutaN}%")
            }            
        }
        }
        render(view:'searchResults', model:['results':results, 'proyectoRutaN':params?.proyectoRutaN, 'fechaCambioD':params?.fechaCambioD, 'fechaCambioH':params?.fechaCambioH, 'lastUpdatedD':'', 'lastUpdatedH':params?.lastUpdatedH]) 
}

, ; , , , .

+1

Source: https://habr.com/ru/post/1751275/


All Articles