Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 2.0-RC1
-
Fix Version/s: 2.0-RC2
-
Component/s: View technologies
-
Labels:None
-
Environment:2.3GHz quad core processor with 4GB of memory running Win 7 x64. The environment is Java JDK version 1.7.0 with JAVA_OPTS set to -XX:MaxPermSize=256M -Xmx768M. GRAILS_HOME is set to version 2.0.0.RC1.
Description
Create an app with a domain of:
class Book {
String title
String state
static constraints = {
title(blank: false, size: 1..40)
state(inList: ['active', 'loginDisabled', 'actionsDisabled'])
}
}
Create the controller and views
Create a command object in src/groovy as follows:
class Operation {
String state
static constraints = {
state(inList: ['active', 'loginDisabled', 'actionsDisabled'])
}
}
Add an action to the Book controller as follows:
def operation(Operation operationInstance) {
operationInstance.state = 'active' // Any valid value will do
return [operationInstance: operationInstance]
}
create an 'operation' gsp that includes a form and within the form add the following input field:
<g:select id="state" name="state" from="${operationInstance.constraints.state.inList}" value="${operationInstance.state}"/>
Run the application and insert a new Book. The select list for the book's state is correctly populated. Now browse to the book/operation page. You will get an error that boils down to:
Caused by MissingPropertyException: No such property: state for class: test.Operation
where 'test' just happened to be the name of my app and thus the default package name also.
The constraints block is a DSL that's parsed to infer the constraint rules. In your example "state(inList: ['active', 'loginDisabled', 'actionsDisabled'])" is actually a method call with name "state" taking a map of parameters. There's no direct way to get access to those parameters from the constraints block.