1
votes

After a user creates a record in my Grails application it takes that information and populates and displays a graph. The user can then click a button on that page and be redirected to the create page. When that happens I would like the previous data entered to be displayed as the defaults for those fields.

In my controller right now we instantiate the domain class.

def create() {
    [apiInstance: new Api(params)]
}

Let's say the Api class contains two properties, a string called name and an integer called myValue.

What do I need to do to show the latest values of name and myValue in the database as the new defaults for the fields in the create page?

1

1 Answers

0
votes

It sounds like you just want to display each field's value?

<g:textField name="name" value="${apiInstance.name}" />
<g:textField name="myValue" value="${apiInstance.myValue}" />

If you want to display the last created Api by default, you have to get that in your controller. You can use last() to get the last created instance of a domain class.

def create() {
    [apiInstance: Api.last() ?: new Api(params)]
}