Reputation: 42
Hi I am just trying out grails and trying to learn more on domain class. I have two simple domain classes:
Domain Class 1
package grailtest
class Person {
String firstName
String lastName
int age
String email
static constraints = {
}
}
Domain Class 2
package grailtest
class Customer {
String customerId
Person personInCharge
static constraints = {
}
}
When I do a run-app, I can only see
grailtest.Person : 1
as the Person. How can I default it to a particular value, for instance firstName + lastName, to make the application more user friendly?
Upvotes: 2
Views: 215
Reputation: 169
You put this code in the view .gsp
${personInstance?.firstname} ${personInstance?.lastname}
Upvotes: 1
Reputation: 50245
You can use @ToString
in case you want an elaborative way of logging or printing in standard out.
import groovy.transform.ToString
@ToString(includeNames=true, includeFields=true)
class Person {
String firstName
String lastName
int age
String email
}
For example,
def person = new Person(firstName: 'Test', lastName: 'hola',
age: 10, email: '[email protected]')
would give
Person(firstName:Test, lastName:hola, age:10, email:[email protected])
Upvotes: 2
Reputation: 766
Find the view where it displays grailstest.Person: 1 and update it to:
${personInstance.firstName} ${personInstance.lastName}
By default this view should be in "views/person"
Upvotes: 1
Reputation: 208
in the domain override toString method to what you wanted to be display. restart the app
Upvotes: 2