换句话说,如何检查作为参数传递给标记的字符串是否对应于“hasMany”关系,并获取相应的域名?
请注意,我可以实例化域类并对其执行getClass—也许它在属性中?我会查的,但任何意见都非常感谢。
代码如下:
*标记以输出域级信息
*
def get_domain_info = { attrs, body ->
// get the domain name for lookup on the Misc Fields XML table
def id = attrs['id']
def domainName = attrs['domain_name']
// get the domainInstance
def domainInstance = grailsApplication.getArtefact("Domain",domainName)?.
getClazz()?.get(id)
def dataNames = attrs['data_names']
def dataNameArray = dataNames.split(",")
out << "<div class=\"dialog\">"
for(dataName in dataNameArray) {
out << "<tr class=\"prop\">"
out << "<td valign=\"top\" class=\"name\">" + dataName + "</td>"
def dataValue = domainInstance[dataName.trim()]
if (dataValue == null){
dataValue = ""
}
def valueLine
if ( dataValue.class == java.sql.Timestamp){
valueLine = "<td valign=\"top\" class=\"value\">" +
dataValue.format("d MMM yyyy") + "</td>"
}
else {
valueLine = "<td valign=\"top\" class=\"value\">" + dataValue + "</td>"
}
out << valueLine
out << "</tr>"
}