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 7630119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:01:04+00:00 2026-05-31T06:01:04+00:00

If I have a page that generates search results based on some ajax components

  • 0

If I have a page that generates search results based on some ajax components and a call to a controller method, what is the best way to save the state of that page (with the search results) so that I can return at any point in the session to see that page again?

1) Search, get results
2) Make some changes on another page
3) Return to search results, see same page as 1 left with.

I’ve read about web flows (which feels unneccessary and more formal than what I need) and AJAX save states, but also seems wrong. Also saw that Grails doesn’t come out of the box with this functionality (which seems weird for a web framework).

Edit:

How do I keep that searchResults list, which is populated by a call form my controller, for that session? I think I’m just missing that bridge between my logic and the session save.

class SearchService {

boolean transaction = false
static scope = 'session'
def searchResults

private Contact[] updateContactSearchList(String ns, Company c, String si, String res) {

    def nameSearch = ns
    def company = Company.get(c?.id)
    def showInactives = si
    def reset = res

    if(res == "true") {
        render(template:'searchResults', model: [searchResults:"", total: 0])
        return
    }

    if(showInactives == "on" && nameSearch == "" && company != null) {

        searchResults = Contact.withCriteria {
            eq('company', company)
            and {
                eq('isActive', false)
            }
        }
       searchResults.sort{it.lastName}
       return searchResults 
    }
    else if(showInactives == "on" && nameSearch == "" && company == null) {

        searchResults = Contact.withCriteria {
            eq('isActive', false)
        }
       searchResults.sort{it.lastName}
       return searchResults 
    }
    else if(showInactives == "on" && nameSearch != "" && company != null) {

       searchResults = Contact.withCriteria {
            eq('company', company)
            and {
                eq('isActive', false)
            }
            or {
                ilike('firstName', '%' + nameSearch + '%')
                ilike('lastName', '%' + nameSearch + '%')
                ilike('fullName', '%' + nameSearch + '%')
            }
        }
       searchResults.sort{it.lastName}
       return searchResults 
    }
    else if(showInactives == "on" && nameSearch != "" && company == null) {

        searchResults = Contact.withCriteria {
            eq('isActive', false)
            or {
                ilike('firstName', '%' + nameSearch + '%')
                ilike('lastName', '%' + nameSearch + '%')
                ilike('fullName', '%' + nameSearch + '%')
            }
        }
       searchResults.sort{it.lastName}
       return searchResults

    }

    else if(showInactives == null && nameSearch == "" && company != null) {

        searchResults = Contact.withCriteria {
            eq('isActive', true)
            and {
                eq('company', company)
            }
        }
       searchResults.sort{it.lastName}
       return searchResults

    }
    else if(showInactives == null && nameSearch == "" && company == null) {

        searchResults = Contact.withCriteria {
            eq('isActive', true)
        }
       searchResults.sort{it.lastName}
       return searchResults

    }
    else if(showInactives == null && nameSearch != "" && company != null) {

        searchResults = Contact.withCriteria {
            eq('isActive', true)
            and {
                eq('company', company)
            }
            or {
                ilike('firstName', '%' + nameSearch + '%')
                ilike('lastName', '%' + nameSearch + '%')
                ilike('fullName', '%' + nameSearch + '%')
            }
        }
       searchResults.sort{it.lastName}
       return searchResults

    }
    else if(showInactives == null && nameSearch != "" && company == null) {

        searchResults = Contact.withCriteria {
            eq('isActive', true)
            or {
                ilike('firstName', '%' + nameSearch + '%')
                ilike('lastName', '%' + nameSearch + '%')
                ilike('fullName', '%' + nameSearch + '%')
            }
        }
       searchResults.sort{it.lastName}
       return searchResults

    }
    else {
        //log error
    }
}

}

  • 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-31T06:01:05+00:00Added an answer on May 31, 2026 at 6:01 am

    I would recommend creating a session scoped service, e.g:

    class SearchService {
        static scope = "session"
        def results
    
    }
    

    this will handle the requests to the search engine and store them in a “results” object. Then, the javascript of the web components should access and render this object directly, without any need to resubmit the query – provided that you want the same results.

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

Sidebar

Related Questions

I have a search page that loads results. Each row has a Delete button
I have a search page which allows users to further filter thier results based
I have an ajax generated search results page which shows all results just fine.
I have a page in one of my client's websites that generates an extensive
I have a server with an asp page on it that generates a report
I have a form that when submitted successfully generates new elements on the page
I have a specialized search engine that passes search criteria from the Search page
On my C# asp.net webform I have a search page that has roughly 20
I have a page called results.aspx . It shows a list of search results.
I have a form bean named SearchForm that I use to display search results.

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.