#GRAILS Search filter gsp not passing parameters to controller

0

I have a form in a gsp page and this form has a g: textField that the user will enter values and then click a button to filter the grid values.

For example: there are 3 records in the grid ... Joaozinho, Jose, Maria. If the user type Joaozinho and click send, it should only appear the results equivalent to Joaozinho.

My form is falling on the controller, but it is not working. I'm using namedQuery in the domain class and I believe I'm passing parameters in the wrong way.

My form code:

<g:form url="[action:'searchByFilter']" method="GET">
                    <p>Filtro de busca</p>
                    <g:textField name="search" params="[search : search]"/>
                    <g:submitButton name="search" class="input-search" 
                    value="${message(code: 'default.button.search.filter')}" />
</g:form>

Code of my Domain class:

static namedQueries = {

    getInvoicesByFilter {
       eq 'description', 'search'
    }
}

The search attribute is the value that was typed in the form input.

Controller code:

def searchByFilter(Invoice invoiceInstance){
   respond Invoice.getInvoicesByFilter.list(params), view: "index"
}

When I click the search button on the form, it is not returning any value, but it should bring, since I have the registry in the database.

What should I do to fix this?

    
asked by anonymous 04.10.2017 / 00:30

2 answers

0

Hello.

In your controller you are using an instance Invoice that you are not using in your form.

def searchByFilter(){
   respond Invoice.getInvoicesByFilter.list(params), view: "index"
}

And on your page try the test

<g:form url="[action:'searchByFilter']" method="GET">
                    <p>Filtro de busca</p>
                    <g:textField name="search"/>
                    <g:submitButton name="searchButton" class="input-search" 
                    value="${message(code: 'default.button.search.filter')}" />
</g:form>

So you do not have duplicate names on your page.

Now if this search is to query only by the name that you will search in the field Description

def searchByFilter(Invoice invoiceInstance){
   respond Invoice.findAllByDescription(params.search), view: "index"
}
    
19.03.2018 / 06:41
1

If you do not send the namedQued attribute to search it will try to filter by the search string.

getInvoicesByFilter { String search ->       
  eq 'description', search
}

I think it would be something like that, and to call:

def pubs = Invoice.getInvoicesByFilter(params.search).list()
    
04.10.2017 / 15:19