thanh
thanh

Reputation: 55

how to display value get from database (grails)

i hava a domain class with some field and i want to get it's value and display in view. controller:

package chat class ChatController{
    def index() {
        def mess = Message.list()
        return [mess: mess]
    } }

and view:

<html>
<body>

    <g:each in="${mess}" var="mess" status="i">

    <h3>${i+1}. ${mess.message}</h3>
    <br/>
    </g:each> </body> </html>

but id doesn't display anything. Where did i wrong ?

Upvotes: 0

Views: 198

Answers (2)

Zoidberg
Zoidberg

Reputation: 571

You shouldn't call your var 'mess' if your list is called 'mess' aswell. That might cause the problem, but I'm not sure about that. Use something different that makes the code more readable. Also check if the list you create in your controller is not empty.

Upvotes: 1

V H
V H

Reputation: 8587

status is your row ID

 <g:each in="${mess}" var="myMess" status="i">



${myMess.id} is what you want to show

${myMess.name} is what you want to show

where name is a defined domainClass value in Message domainClass

Upvotes: 1

Related Questions