Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to filter #44

Closed
patrickhousley opened this issue Mar 2, 2014 · 13 comments
Closed

Unable to filter #44

patrickhousley opened this issue Mar 2, 2014 · 13 comments

Comments

@patrickhousley
Copy link

I have a grid setup using GORM and Source as the domain object. I am trying to add a column that uses a value several domains up in the hierarchy. Specifically environmentendpoint.cepenvironment.cep.name where name is a property of the Cep domain. Each domain in the hierarchy has a belongsTo association with the next domain in the hierarchy. I can get the value no problem but am unable to filter on it.

"environmentendpoint.cepenvironment.cep.name" {
                    label "CEP"
                    type "text"
                    value { source->
                        source.environmentendpoint.cepenvironment.cep.name
                    }
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['eq', 'cn']}"
                    }
                }
dataSourceType "gorm"
            domainClass Source
            inlineEdit false
            enableFilter true
            jqgrid {
                rownumbers true
            }
            globalFilterClosure {params ->
                switch(params.searchOper) {
                case "eq":
                    eq(params.searchField, params.searchString)
                    break
                case "cn":
                    ilike(params.searchField, "%" + params.searchString + "%")
                    break
                }
            }

I am trying to use the globalFilterClosure because I am making use of the search feature in jqGrid. However, I have tried adding a filterClosure to the column with no luck. Below is the error I keep getting.

Error |
2014-03-02 11:52:06,059 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - QueryException occurred when processing request: [GET] /CEPInformation/sourcelistgrid/sourceListRows - parameters:
sord: asc
searchOper: eq
searchString: sm
page: 1
nd: 1393782726001
searchField: environmentendpoint.cepenvironment.cep.name
sidx: 
format: 
filters: 
rows: 100
_search: true
could not resolve property: environmentendpoint.cepenvironment.cep.name of: com.cerner.cep_information.domain.Source. Stacktrace follows:
Message: could not resolve property: environmentendpoint.cepenvironment.cep.name of: com.cerner.cep_information.domain.Source

By the way, I have also tried using:

def rusults = Source.findAll{
    environmentendpoint.cepenvironment.cep.name =~ params.searchString
}

I don't get an error with this but I also don't get any filtering.

By the way, sort is misspelled in the request params being sent to the server. This is probably on the jqGrid side.

@tudor-malene
Copy link
Owner

Hi Patrick,

The filterClosure should look like this:

"environmentendpoint.cepenvironment.cep.name" {
                    label "CEP"
                    type "text"
                    // you can comment the value and it should work
                    value { source->
                        source.environmentendpoint.cepenvironment.cep.name
                    }
// you need to nest the relationships 
                    filterClosure{ filter->
                       source{
                         environmentendpoint{
                                cepenvironment{
                                     ilike('name', "%${filter.paramValue}%")
                                }
                          }
                       }
                    }
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['eq', 'cn']}"
                    }
                }

Let me know how this goes, and then we'll see with the other issues.

@patrickhousley
Copy link
Author

I tried that but I am still getting an error.

Error |
2014-03-03 15:25:48,790 [http-bio-8080-exec-10] ERROR errors.GrailsExceptionResolver  - MissingMethodException occurred when processing request: [GET] /CEPInformation/sourcelistgrid/sourceListRows - parameters:
sord: asc
page: 1
nd: 1393881948557
environmentendpoint.cepenvironment.cep.name: SM
sidx: 
format: 
rows: 100
_search: true
No signature of method: grails.gorm.DetachedCriteria.source() is applicable for argument types: (com.cerner.cep_information.controller.SourcelistgridController$__clinit__closure1_closure2_closure5_closure11_closure21_closure22) values: [com.cerner.cep_information.controller.SourcelistgridController$__clinit__closure1_closure2_closure5_closure11_closure21_closure22@31ca9ab7]
Possible solutions: sort(java.lang.String), count(), collect(), count(groovy.lang.Closure), count(java.util.Map), or(groovy.lang.Closure). Stacktrace follows:
Message: No signature of method: grails.gorm.DetachedCriteria.source() is applicable for argument types: (com.cerner.cep_information.controller.SourcelistgridController$__clinit__closure1_closure2_closure5_closure11_closure21_closure22) values: [com.cerner.cep_information.controller.SourcelistgridController$__clinit__closure1_closure2_closure5_closure11_closure21_closure22@31ca9ab7]
Possible solutions: sort(java.lang.String), count(), collect(), count(groovy.lang.Closure), count(java.util.Map), or(groovy.lang.Closure)
    Line | Method
->>  873 | methodMissing    in grails.gorm.DetachedCriteria
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     78 | doCall           in com.cerner.cep_information.controller.SourcelistgridController$__clinit__closure1_closure2_closure5_closure11_closure21
|    904 | handleJunction . in grails.gorm.DetachedCriteria
|    181 | and              in     ''
|    205 | doCall . . . . . in org.grails.plugin.easygrid.datasource.GormDatasourceService$_createWhereQuery_closure7
|    202 | createWhereQuery in org.grails.plugin.easygrid.datasource.GormDatasourceService
|    172 | list . . . . . . in     ''
|     77 | callDSList       in org.grails.plugin.easygrid.EasygridDispatchService
|     82 | gridData . . . . in org.grails.plugin.easygrid.EasygridService
|     72 | doCall           in org.grails.plugin.easygrid.EasygridInitService$_registerControllerMethods_closure4
|    207 | guard . . . . .  in org.grails.plugin.easygrid.EasygridService
|    111 | doCall           in org.grails.plugin.easygrid.EasygridInitService$_registerControllerMethods_closure9_closure17
|    191 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter         in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker . . .  in java.util.concurrent.ThreadPoolExecutor
|    615 | run              in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . . . .  in java.lang.Thread

@tudor-malene
Copy link
Owner

I misread your example.

Try this:

   filterClosure{ filter->
                         environmentendpoint{
                                cepenvironment{
                                    cep{
                                       ilike('name', "%${filter.paramValue}%")
                                    }
                                }
                          }
                    }

@patrickhousley
Copy link
Author

I tried that as well and get the below error. I am really at a loss on making this work.

Error |
2014-03-05 13:02:40,648 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - QueryException occurred when processing request: [GET] /CEPInformation/sourcelistgrid/sourceListRows - parameters:
sord: asc
page: 1
nd: 1394046160538
environmentendpoint.cepenvironment.cep.name: sc
sidx: 
format: 
rows: 100
_search: true
could not resolve property: cepenvironment of: com.cerner.cep_information.domain.Source. Stacktrace follows:
Message: could not resolve property: cepenvironment of: com.cerner.cep_information.domain.Source
    Line | Method
->>  686 | doCall               in grails.gorm.DetachedCriteria$_count_closure4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    931 | doCall               in grails.gorm.DetachedCriteria$_withPopulatedQuery_closure10
|    694 | doCall . . . . . . . in org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure23
|    302 | execute              in org.grails.datastore.mapping.core.DatastoreUtils
|     37 | execute . . . . . .  in org.grails.datastore.gorm.AbstractDatastoreApi
|    693 | withDatastoreSession in org.grails.datastore.gorm.GormStaticApi
|    913 | withPopulatedQuery . in grails.gorm.DetachedCriteria
|    684 | count                in     ''
|    683 | count . . . . . . .  in     ''
|    192 | countRows            in org.grails.plugin.easygrid.datasource.GormDatasourceService
|     87 | callDSCountRows . .  in org.grails.plugin.easygrid.EasygridDispatchService
|     83 | gridData             in org.grails.plugin.easygrid.EasygridService
|     72 | doCall . . . . . . . in org.grails.plugin.easygrid.EasygridInitService$_registerControllerMethods_closure4
|    207 | guard                in org.grails.plugin.easygrid.EasygridService
|    111 | doCall . . . . . . . in org.grails.plugin.easygrid.EasygridInitService$_registerControllerMethods_closure9_closure17
|    191 | doFilter             in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker            in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run                  in java.lang.Thread

@tudor-malene
Copy link
Owner

Could you show me the entire grid definition you used? ( or at least the column where it fails)

@patrickhousley
Copy link
Author

package com.cerner.cep_information.controller

import org.grails.plugin.easygrid.Easygrid
import org.grails.plugin.easygrid.Filter
import org.springframework.dao.DataIntegrityViolationException
import com.cerner.cep_information.domain.*

@Easygrid
class SourcelistgridController {
    static grids = {
        sourceList {
            dataSourceType "gorm"
            domainClass Source
            inlineEdit false
            enableFilter true
            jqgrid {
                rownumbers true
            }
            globalFilterClosure {params ->
                /*switch(params.searchOper) {
                case "eq":
                eq(params.searchField, params.searchString)
                break
                case "cn":
                ilike(params.searchField, "%${filter.paramValue}%")
                break
                }*/
            }
            columns {
                id {
                    label "ID"
                    jqgrid {
                        hidden = true
                    }
                }
                name {
                    label "Name"
                    type "text"
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['eq', 'cn']}"
                    }
                }
                systemcodes {
                    label "System Codes"
                    type "text"
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['cn']}"
                    }
                }
                sourceaddress {
                    label "Source Address"
                    type "text"
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['cn']}"
                    }
                }
                islive {
                    label "Live"
                    type "boolean"
                    jqgrid {
                        search false
                    }
                }
                "environmentendpoint.cepenvironment.cep.name" {
                    label "CEP"
                    type "text"
                    value { source->
                        source.environmentendpoint.cepenvironment.cep.name
                    }
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['eq', 'cn']}"
                    }
                    filterClosure{ filter->
                        environmentendpoint {
                            cepenvironment {
                                cep {
                                    ilike('name', "%${filter.paramValue}%")
                                }
                            }
                        }
                    }
                }
                "environmentendpoint.networkurl" {
                    label "Network URL"
                    type "text"
                    value { source->
                        source.environmentendpoint.networkurl
                    }
                    jqgrid {
                        search true
                        searchoptions "{sopt: ['cn']}"
                    }
                }
                "environmentendpoint.functionality" {
                    label "Endpoint Functionality"
                    type "text"
                    value { source->
                        source.environmentendpoint.functionality
                    }
                    jqgrid {
                        search false
                    }
                }
            }
        }
    }

    def index() {}
}

@tudor-malene
Copy link
Owner

The grid looks good.

I don't understand this error message

could not resolve property: cepenvironment of: com.cerner.cep_information.domain.Source

Were you able to write a working criteria or a where query?

@patrickhousley
Copy link
Author

The grid definition shows that I am retrieving the value of source.environmentendpoint.cepenvironment.cep.name. I also wrote the below query in the page controller to show that the data can be queried.

package com.cerner.cep_information.controller

import grails.converters.JSON
import com.cerner.cep_information.domain.Source

class SourceController {
    def sourcedaoService

    def list() {
        def r = Source.findAll {
            environmentendpoint {
                cepenvironment {
                    cep {
                        ilike("name","S%")
                    }
                }
            }
        }
        println r as JSON

        render(view: "list.gsp")
    }
}

The above query prints the expected value to the console.

@tudor-malene
Copy link
Owner

So basically, the grid displays the data, but throws that error when you want to filter on the "environmentendpoint.cepenvironment.cep.name" column?

Everything looks good from what you showed me until now.

Is it possible to create a small project to reproduce the error?

Thanks

@patrickhousley
Copy link
Author

I am thinking this issue is related to #21. I have my domain objects setup as so:

Cep hasMany Cepenvironment hasMany Environmentendpoint hasMany Source

There is a reverse reference as well to ensure bi-directional access:

Source belongsTo Environmentendpoint belongsTo Cepenvironment belongsTo Cep

Let me know if you would agree my issue is similar to issue 22.

@patrickhousley
Copy link
Author

I was able to get the filtering to work using the below code. I am going to have to add a check in the globalFilter to perform special filtering if the field name is 'environmentendpoint.cepenvironment.cep.name'. It would be nice to see this resolved but for now, at least I can filter.

filterClosure{ filter->
                        def eeps = Environmentendpoint.findAll {
                            cepenvironment{
                                cep{
                                    name =~ "%${filter.paramValue}%"
                                }
                            }
                        }
                        if (eeps != []) {
                            'in'("environmentendpoint", eeps)
                        } else {
                            eq("id", null)
                        }
                    }

@tudor-malene
Copy link
Owner

Hi Patrick,

I'll try to reproduce the problem and let you know.
It could be related to the other issue.

Thanks

@tudor-malene
Copy link
Owner

Hi Patrick,

I replaced DetachedCriteria (which seems to be quite buggy) with Criteria in the Gorm implementation, in easygrid:1.5.0.
Now it should work properly.

Let me know if you give it a try.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants