Wednesday 15 June 2011

list - How to add items to an array one by one in groovy language -


I am developing a grails app, and I already have a domain class "ExtendedUser" in which users I have the information: Name "," Bio "," Birthday ", now I am planning to make data about the age of the user, so I have created another controller" statistician "and it is an idea that all birthdays are given as a local To arrange in the array so that I can calculate many

  Category Statistics Controller {// @Secured (["ROLE_COMPANY"]) def teststat () {def user = ExtendedUser.findAll () // A list with all users DEF EmptyList = [] // AN empty list to keep all birth placements in def k = 0 while (k & lt; = user.size ()) {emptyList.add (user [k]. Birthdate) // To empty a Add new birthdate (error) k ++} [age: user]}}   

When I test, I see this error message: 'Date property on zero object' 'Not received Can So my question is that all birthday a single array or list, so I can calculate with it. Thanks

I am as much as possible in groovy. Read about Groovy Looping

Try something like this:

  user.each () {emptylist.push (it.birthdate) // 'this' default The name of the errator is .each ()}   

I do not have the Gayle environment installed on this computer, which is correct without checking from top of my head but giving it a shot.

No comments:

Post a Comment