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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:09:58+00:00 2026-05-26T14:09:58+00:00

This may be a basic question but I am new to grails and tried

  • 0

This may be a basic question but I am new to grails and tried looking for a solution.
I need to have a global variable in my groovy controller, a list for example, which is updated in one of the closures (def) and its value is updated in that def,
this new value for the list should be available in other closure/def.
I tried simply:

class MyController {
  def myList = []

  def def1 = { myList = someList.clone();}

  def def2 = { println myList}
}

The value of myList should be displayed as the updated value from def1, right now it stays empty. Would static help? or is there a method to pass variables between closures directly, since I dont want the huge list to be passed to GSP and back in the second def.

  • 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-26T14:09:59+00:00Added an answer on May 26, 2026 at 2:09 pm

    Your controllers should stay stateless. Controllers are instantiated at each action request, so your member variable myList will be thrown away between actions. If you define it static, it will be shared by all instances of MyController.

    If you define myList static, all clients accessing your controller will get the same result. If that’s what you want, your list should probably be stored through domain objects in your database (see chapter 5 of Grails documentation, Object Relational Mapping).

    If you want each client to have their own myList shared between controller actions, what you are looking for are called web flows. They provide a mechanism to store state between Controller actions performed by a given client. Web flows are documented in Grails documentation (Chapter 6 – The Web Layer).

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

Sidebar

Related Questions

I'm new to C#, so this may be a basic question. What I need
I'm new to C++, so this question may be basic: I have two classes
This may be a basic question but I am pretty new to DDD. I
I am new to Android, so this may seem like a basic question. But
This may be a basic question but how can I include a module with
This may be a very basic question. But I am finding it confusing with
This may be a basic C# question, but I'm comming from a C/C++ background.
This may be a basic question but why can't I cast a generic type
I am new in programming and this question may really be stupid but I
This may seem like a basic question, but I am not getting how to

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.