Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 870737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:31:35+00:00 2026-05-15T10:31:35+00:00

I am trying to make a filter for my data so other people can

  • 0

I am trying to make a filter for my data so other people can see it, lets say I have a bunch of Events, like a calendar, and I want to see all that have a name or title with the word “Soccer”.
I’ve been trying to figure out how to do it but nothing works for me, I also tried to use filterPane plugin but did not work quite as well and I prefer to write something myself and maybe upload it to the Grails plugins webpage for future references,

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:31:36+00:00Added an answer on May 15, 2026 at 10:31 am

    If it’s in a domain class try:

    def matches = Book.findAllByTitleLike("wonderful")
    

    of if you don’t want to worry about upper/lower case:

    def matches = Book.findAllByTitleILike("wonderful")
    

    If your book titles are in a collection:

    def books = ['Wonderful Tonight', 'Atlas Shrugged', 'A Tale of Two Cities']
    def matches = books.findAll{it.indexOf("wonderful") > -1} // returns []
    matches = books.findAll{it.indexOf("Wonderful") > -1} // returns ['Wonderful Tonight']
    matches = books.findAll{it.toLowerCase().indexOf("wonderful") > -1} // returns ['Wonderful Tonight']
    

    Update:

    So now that we have a more complete description of your problem, let’s figure out a simplified way to solve it.

    Today, you want to search by event title and its date so we’ll start there then look at how we might generalize this and make more complete solution down the road.

    Our general flow is going to be something like:

    1. You display a search form to your user
    2. User enters a date and/or title to search for and submits the form
    3. You find the matching entries
    4. You display the matching entries to the user

    First, let’s create a view for the search form, in grails-app/views/entry/ create a file called search.gsp with the following content:

    <g:form controller='entry' action='searchResults'>
       Entry Title: <g:textField name="title" value="${title}" />
       Entry Date: <g:datePicker name="day" value="${day}" precision="day" />
       <g:submitButton name="submit" value="Search" />
    </g:form>
    

    Next, we’ll create the controller. In grails-app/controllers/ create a new controller EntryController.groovy. You can do this by executing the ‘grails create-controller Entry’ if you don’t already have the EntryController created.

    Now, we’ll create two controller closures:

    def search = {
      render(view:'search')
    }
    

    and

    def searchResults = {
      def entryCriteria = Entry.createCriteria()
      def results = entryCriteria.list {
        if(params?.title) {
          ilike{"title","%${params.title}%"
        }
        if(params?.day) {
          eq("eventDate", params.day)
        }
      }
      render(view:'searchResults', model:['results':results])
    }
    

    Finally, let’s create a searchResults.gsp in grails-app/views/entry

    <h1>Results</h1>
    <g:each in=${results}>
      ${it}
    </g:each>
    

    So, now putting it all together:

    1. Run your app and go to localhost:8080/${appName}/entry/search, and that should bring up your search form.
    2. Enter a title and/or date, submit the form and that should send your form data into the searchResults closure in your controller
    3. The criteria search in the closure will find all the Entries that match your search criteria
    4. You render the search results view and pass it your matching entries, then on the gsp we loop through each of the results and display it.

    As a disclaimer, I’m writing this code on the fly in the stack overflow text editor, so I won’t be surprised if there are a couple syntax issues that I missed. Hopefully the explanation will be enough to get you on your way. Now let’s talk about taking this basic example and polishing it up to a more respectable solution.

    I would recommend you try to do the following after you get the hang of this basic example:

    1. Try building a command object to represent your search form, it will allow you to validate your user’s input and is a more manageable approach than dealing directly with the request parameters like I did above.
    2. Build some unit tests for your command object and the controller flow; check that error messages are being populated for your various validations.
    3. Take the criteria search that we have defined in the searchResults closure, and move it out to a separate Grails Service, pass your command search object to the service to get your results. Then, you can re-use the search functionality if you need it else where in your application later.
    4. Build some unit tests for your service; mock out the Entry domain object and verify that your search functionality is working correctly.

    If you’re struggling to get the above solution to work, try to simplify it even further. Eliminate the date search and just search by title. Replace all the criteria logic in the searchResults action with:

    def results = Entry.findByTitleILike(params?.title)
    

    Start simple and improve and you’ll get the hang of it in no time.

    Good Luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.