Technique No-1:
If Value String (Key with cotation):
<g:select id=”active” name=”active” from=”${[‘Enabled’,’Disabled’]}” keys=”${[‘A’,’B’]}” value=”${afmCalendarInstance?.calendarType}” />
If Value Integer (Key without cotation):
<g:select id=”active” name=”active” from=”${[‘Enabled’,’Disabled’]}” keys=”${[1,2]}” value=”${afmCalendarInstance?.calendarType}” />
Technique No-2 :
# In domain Class:
class Sponsorship {
String contributionType
static constraints = {
contributionType(inList:[“Other” , “Venue” , “A/V” , “Promotion” , “Cash”,”Maruf” ])
}
}
# In .gsp page
<g:fieldValue bean=”${tekEventInstance}” field=”venue”/>
It will show as comboo with value….
—————————————————————————————————————-
Technique No-3 :
– ‘belongsTo’ is used to show that another class is the owning side of a relationship. It is
used for one-to-many and many-to-many relationships.
class Parent {
…
static hasMany = [children:Child]
}
class Child {
…
Parent parent
static belongsTo = Parent
}
========================Example====================
class Message {
String subject
TekEvent event
static constraints = {
subject(blank:false)
}
static belongsTo = TekEvent
}
class TekEvent {
String city
String name
String description
static hasMany = [ messages:Message]
static constraints = {
name()
city()
description(maxSize : 5000)
messages(nullable : true)
}
}
# ‘toString()’
class Message {
String subject
String content
TekEvent event
String toString(){ subject }
static constraints = {
subject(blank:false)
content(blank:false, maxSize:2000)
}
static belongsTo = TekEvent
}
# class TekEvent {
String city
String name
String description
static hasMany = [ messages:Message]
static constraints = {
name()
city()
description(maxSize : 5000)
messages(nullable : true)
}
}
# <g:each in=”${tekEventInstance.volunteers}” var=”v”>
<g:link controller=”tekUser” action=”show” id=”${v.id}”>
${v?.encodeAsHTML()}
</g:link>
</span>
</g:each>
NB.- For writing the line “String toString(){ subject }” in class Message in .gsp page result will be against “${v?.encodeAsHTML()}” the line will be the value of “subject” column.
If the line “String toString(){ subject }” in class Message in .gsp page result will be against “${v?.encodeAsHTML()}” the line will be “tekdays.Message : 1” i.e.”parentClassName.childClassName:childClassId(PK)value”
//
Leave a comment