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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:40:51+00:00 2026-05-23T11:40:51+00:00

I cant get the g:each to work. I am trying to iterate over anything

  • 0

I cant get the g:each to work. I am trying to iterate over anything but it never works = doesnt generate any html.

index.gsp

<g:each var="i" in="${userList}" controller="user">
          <li>Item ${i.name}</li>
</g:each>

userController.groovy

class UserController {
    ...        
        def userList = {

            User.list()

        }
        ...
}

Then I have User.groovy filled with number of users..

What am i supposed to write in in=”${…..}” to iterate for example over users declared as User.groovy ? I have tried : User, users, User.list() …

Thanks

EDIT:

Let’s say i have a

def findOne {

 [users : User.findAllByNameLike("%Petr%")

}

in my UserCotroller.

How do i use g:each for it because

<g:each var="user" in="${findOne}"> 

won’t do anything..

  • 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-23T11:40:51+00:00Added an answer on May 23, 2026 at 11:40 am

    In your example. userList is a Closure, so it’s the action name, so I’m assuming you’re accessing http://localhost:8080/appname/user/userList

    If you return something from a controller action to be rendered in the GSP, it has to be in a Map, the “model”. Each value in the map is exposed in the GSP using the map key as its name. So the controller action corresponding to your GSP would be

    def userList = {
        [users: User.list()]
    }
    

    and then you can iterate with

    <g:each var="user" in="${users}">
        <li>Item ${user.name}</li>
    </g:each>
    

    The name doesn’t matter – it just has to be the same in the model map as in the GSP.

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

Sidebar

Related Questions

im trying to implement a getBounds() method, but i cant get union to work;
Cant get this script to work with my menu really have tried everything any
I'm probably doing something realy stupid but I cant get this to work: var
I cant seem to get this to work. Im trying to do two things
I cant get this to work. I am trying to replace certain characters when
I have been trying since yesterday to get google like paging, but each time
Can someone explain why i cant get the desired delay between each request? They
I cant get jquery's date picker to work on my page. I have a
Probably I cant get more dumb, but seriously this is the first time I
I have an issue I cant get to the bottom of, so any help

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.