Home Setting domain class property values with GORM
Reply: 1

Setting domain class property values with GORM

Sulteric
1#
Sulteric Published in 2018-01-03 15:19:44Z

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?

doelleri
2#
doelleri Reply to 2018-01-04 00:38:37Z

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)]
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302995 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO