using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

stuart.simpson
I am trying to create the following view:

  <g:each status="i" in="${roles}" var="role">
  <div class="${(i%2)==0 ? "even":"odd"} row" id="${role.id}">
  <div class="column">${role.name}</div>
  <div class="column">${role.crated_by}</div>
  <div class="column">${role.dateCreated}</div>
  <div class="column">${role.updated_by}</div>
  <div class="column">${role.lastUpdated}</div>
  </div>
  </g:each>
the groovy object is defined as:

import java.util.Date;

class Role {

        String name
        Date dateCreated
        Date lastUpdated
        String created_by
        String updated_by
       
        static hasMany = [role_services: Role_Service]

        static mapping = {
                id generator:'sequence', params:[sequence:'ROLE_SEQ']
                dateCreated column: 'CREATION_DATE'
                lastUpdated column: 'UPDATE_DATE'
                version false
        }
               
    static constraints = {
    }
}

the controller is defined as:

class RoleController {

    def scaffold = Role
       
        def roleForm(){
                def roles = [roles: Role.executeQuery("Select name, created_by, dateCreated, updated_by, lastUpdated from Role r")]
                render( view: "roleServicesForm", model: roles)
        }
}

I am getting the following error:

Exception evaluating property 'id' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: id for class: java.lang.String

I would expect the roles variable to be defined as an array.  However i would not expect any of the attributes Role to be defined as an array.  the error occurs regardless of which attribute is used from the Role object.  I have searched he form and Google without successes.

I belive it is how i have my controller defined that might be giving me the problem.  Thanks for  any help you can give me.

Stu

Reply | Threaded
Open this post in threaded view
|

Re: using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

longwa
Why are you using executeQuery()?

Why not just Role.list() which returns a list of Role objects.

  def roleForm(){
       render( view: "roleServicesForm", model: [roles: Role.list()] )
  }

Also, your view has a typo in crated_by, which would fail too.

-Aaron

On Fri, Jun 15, 2012 at 2:33 PM, stuart.simpson <[hidden email]> wrote:
I am trying to create the following view:

                       <g:each status="i" in="${roles}" var="role">
                               <div class="${(i%2)==0 ? "even":"odd"} row" id="${role.id}">
                                       <div class="column">${role.name}</div>
                                       <div class="column">${role.crated_by}</div>
                                       <div class="column">${role.dateCreated}</div>
                                       <div class="column">${role.updated_by}</div>
                                       <div class="column">${role.lastUpdated}</div>
                               </div>
                       </g:each>
the groovy object is defined as:

import java.util.Date;

class Role {

       String name
       Date dateCreated
       Date lastUpdated
       String created_by
       String updated_by

       static hasMany = [role_services: Role_Service]

       static mapping = {
               id generator:'sequence', params:[sequence:'ROLE_SEQ']
               dateCreated column: 'CREATION_DATE'
               lastUpdated column: 'UPDATE_DATE'
               version false
       }

   static constraints = {
   }
}

the controller is defined as:

class RoleController {

   def scaffold = Role

       def roleForm(){
               def roles = [roles: Role.executeQuery("Select name, created_by,
dateCreated, updated_by, lastUpdated from Role r")]
               render( view: "roleServicesForm", model: roles)
       }
}

I am getting the following error:

Exception evaluating property 'id' for java.util.Arrays$ArrayList, Reason:
groovy.lang.MissingPropertyException: No such property: id for class:
java.lang.String

I would expect the roles variable to be defined as an array.  However i
would not expect any of the attributes Role to be defined as an array.  the
error occurs regardless of which attribute is used from the Role object.  I
have searched he form and Google without successes.

I belive it is how i have my controller defined that might be giving me the
problem.  Thanks for  any help you can give me.

Stu



--
View this message in context: http://grails.1312388.n4.nabble.com/using-g-each-with-error-Exception-evaluating-property-id-for-java-util-Arrays-ArrayList-tp4630213.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

stuart.simpson
Thanks Aaron for the help and the info.  The change to the  controller worked.  However, one reason for using the executeQuery was I wanted to be able to dynamically alter the from and where clause rather than returning the entire list.  The select statement was just kept simple to eliminate errors in the select statement to start with.   I would like to try and figure out how to use the executeQuery if possible.
Reply | Threaded
Open this post in threaded view
|

Re: using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

longwa
Well, you are creating an HQL query so you don't have to indicate the columns that you want. Once you provide the select part of the query, you are going to get an Array instead of a GORM object.

So, doing Roles.executeQuery("from Roles where ....") should return a list of Role objects but Roles.executeQuery("select ... from Roles") will return an Array.

In your first example, you didn't have the "id" field in your query, so it wouldn't be in the array, which may have caused the error.

-Aaron

On Fri, Jun 15, 2012 at 5:02 PM, stuart.simpson <[hidden email]> wrote:
Thanks Aaron for the help and the info.  The change to the  controller
worked.  However, one reason for using the executeQuery was I wanted to be
able to dynamically alter the from and where clause rather than returning
the entire list.  The select statement was just kept simple to eliminate
errors in the select statement to start with.   I would like to try and
figure out how to use the executeQuery if possible.

--
View this message in context: http://grails.1312388.n4.nabble.com/using-g-each-with-error-Exception-evaluating-property-id-for-java-util-Arrays-ArrayList-tp4630213p4630222.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

RE: using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

stuart.simpson

Thank makes sense.  I appreciate your help.

 

From: Aaron Long [via Grails] [mailto:[hidden email]]
Sent: Friday, June 15, 2012 3:09 PM
To: Stuart Simpson
Subject: Re: using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList

 

Well, you are creating an HQL query so you don't have to indicate the columns that you want. Once you provide the select part of the query, you are going to get an Array instead of a GORM object.

 

So, doing Roles.executeQuery("from Roles where ....") should return a list of Role objects but Roles.executeQuery("select ... from Roles") will return an Array.

 

In your first example, you didn't have the "id" field in your query, so it wouldn't be in the array, which may have caused the error.

 

-Aaron

On Fri, Jun 15, 2012 at 5:02 PM, stuart.simpson <[hidden email]> wrote:

Thanks Aaron for the help and the info.  The change to the  controller
worked.  However, one reason for using the executeQuery was I wanted to be
able to dynamically alter the from and where clause rather than returning
the entire list.  The select statement was just kept simple to eliminate
errors in the select statement to start with.   I would like to try and
figure out how to use the executeQuery if possible.

--
View this message in context: http://grails.1312388.n4.nabble.com/using-g-each-with-error-Exception-evaluating-property-id-for-java-util-Arrays-ArrayList-tp4630213p4630222.html

Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email

 

 


To unsubscribe from using <g:each> with error: Exception evaluating property 'id' for java.util.Arrays$ArrayList, click here.
NAML