I call an index method within a controller
def index() {
childInstance = Child.get(params.id)
if(childInstance){
System.out.println("CHILD" + childInstance.firstname)
def messages = currentUserTimeline()
[profileMessages: messages,childInstance:childInstance]
} else {
def messages = currentUserTimeline()
[profileMessages: messages]
System.out.println("ALL")
}
}
in the gsp page I have
${childInstance.firstname}
Which if i pass a childInstance this is fine but if I don’t i get a 500 because of a null pointer is there a way I can do an if statement in a gsp so i can do this
if(childInstance){
${childInstance.firstname}
} else {
All
}
You can use
g:if,g:elseifandg:else: