views:

147

answers:

1

Hi! 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.

+1  A: 

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}

Dave
Thanks! I found the error. It was at the controller as you thought.
Luixv