Reputation: 8710
I have an application written in grails.
I want to add a new domain class with default initial values.
These values should appear as default or initial values
under the create view.
I mean, the generated inout field tag should have this value as
an attribute.
The class (simplified) look as follows:
class Whatever{
static constraints = {
myString(blank:false, nullable:false)
}
String myString = "hallo"
The generated view looks as follows:
...
<td valign="top" class="value ${hasErrors(bean: whatEverInstance, field: 'myString', 'errors')}">
<g:textField name="serviceReview" value="${fieldValue(bean: whatEverInstance, field: 'myString')}" />
</td>
For some unknown reason when the source of render page has looks as follows:
<td valign="top" class="value ">
<input type="text" name="myString" value="" id="myString" />
</td>
I was expecting value="hallo".
I mean:
<td valign="top" class="value ">
<input type="text" name="myString" value="hallo" id="myString" />
</td>
What am I doing wrong?
Thanks in advance,
Luis
EDIT:
My create method is as follows:
def create = {
def whateverInstance = new Whatever()
whateverInstance.properties = params
return [whateverInstance: whateverInstance]
}
But the create method is called after the form is filled.
Upvotes: 0
Views: 5433
Reputation: 21
int varm
static mapping = {
table 'Test55'
id column: "kid", name:"kid"
version false
varm column: 'varm', name: 'varm', sqlType: 'numeric(1) default 1'
}
This works
Upvotes: 2
Reputation: 3557
Is you whatEverInstance bean being set in the controller's create
setup action?
def create = {
[whateverInstance: new Whatever()]
}
You could test the value of whateverInstance in the gsp with:
${whateverInstance}
Upvotes: 1