IAmYourFaja
IAmYourFaja

Reputation: 56944

How to inject domain constraints into a Grails GSP?

My domain object:

class Fizz {
    String buzz

    static constraints = {
        buzz (blank: false, inList: ['foo', 'bar'])
    }
}

My controller:

class FizzController {
    def index() {
        render(
            view: "fizz",
            model: [
            ]
        )
    }
}

Inside the <body> tag of my GSP (fizz.gsp):

<label for="buzz">Buzz:</label>
<g:select name="buzz" from="${Fizz.constraints.buzz.inList}" />

When I run the app I get a runtime exception rendering the page, stating:

Cannot get property 'constraints' on null object

So Fizz is null, which tells me I'm not injecting the GSP correctly. It may have something to do with my empty model array (back in the controller):

model: [
]

But since I'm accessing a static property here, I'm not sure how to inject the model with a static value (if that is even the cause of what's happening here).

Upvotes: 1

Views: 519

Answers (1)

injecteer
injecteer

Reputation: 20707

you have to import the class in your gsp:

 <%@ page import="com.someapp.Fizz" %>

Upvotes: 1

Related Questions