Grails access value from belongsTo in domain?
-
09-07-2021 - |
سؤال
I am working on a Grails project and I have a User domain model with the following:
class SecUser {
transient springSecurityService
String username
String email
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static belongsTo = [area:Areas]
.....
}
I am also using the springSecurityUI and I have this on the create user view:
<s2ui:textFieldRow readonly='yes' name='area' labelCode='user.area.label' bean="${user}"
labelCodeDefault='Area' value="${area}"/>
When I see the create view instead of seeing the box for area populate with the area of the current logged in user I can see the following:
com.testapp.Areas : 1
I am presuming this is the id of the Dept for this user but I want to show the actual value, how can I do this for relational objects?
Thanks for the help
EDIT.......
Below is my Areas class as it stands
class Areas {
String name
static hasMany = [users:SecUser]
}
EDIT...
I have now fixed this using:
value="${area.name}"
المحلول
If you just want to display the actual id attribute, then you can do so like this:
<s2ui:textFieldRow readonly='yes' name='area' labelCode='user.area.label' bean="${user}"
labelCodeDefault='Area' value="${area?.id}"/>
نصائح أخرى
com.testapp.Areas : 1
is the output of the default toString()
method. To change the output, you need to write your own toString()
on Areas
.
class Areas {
String toString() {
"the actual string representation of my Areas object"
}
}