#GRAILS gsp search filter not passing parameters to controller

Asked

Viewed 220 times

0

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

For example: there are 3 registers on the grid... Joaozinho, Jose, Maria. Se o usuário digitar Joaozinho e clique em enviar, deverá aparece apenas os resultados equivalente a Joaozinho.

My form is falling into the controller, but it’s not working. I am using namedQuery in the Domain class and I believe I am passing parameters incorrectly.

Code of my form:

<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 refers to the value that was entered in the form input.

Controller code:

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

When I click on the search button of the form, is not returning any value, but should bring, because I have the registration in the bank.

What should I do to fix this problem?

2 answers

1

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

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

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

def pubs = Invoice.getInvoicesByFilter(params.search).list()

0


Hello.

On your Voce 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 Voce does not have duplicate names on your page.

Now if this search is to be queried only by the name you will search in the Description field

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.