我是
真的?
喜欢格雷斯。几周前,当我第一次使用它的时候,我没有意识到它是一种成熟的语言。事实上,不止这些。它是一个完整的Web堆栈,包含一个Web服务器和一个数据库。总之,我问题的简短回答是肯定的。你甚至可以说是的,当然!以下是我创建的taglib的代码:
import org.maflt.flashlit.pojo.Item
import org.maflt.flashlit.pojo.ItemTag
import org.maflt.flashlit.pojo.Metacollection
import org.maflt.flashlit.pojo.SetTagtype
import org.maflt.flashlit.pojo.Tag
import org.maflt.flashlit.pojo.Tagtype
/**
* @return Input form fields for all fields in the given Collection's Metadataset. Does not return ItemTags where TagType is not in the Metadataset.
*
* In Hibernate, the
*
* "from ItemTag b, Tag a where b.tag= a"
*
* query is a cross-join. The result of this query is a list of Object arrays where the first item is an ItemTag instance and the second is a Tag instance.
*
* You have to use e.g.
*
* (ItemTag) theTags2[0][0]
*
* to access the first ItemTag instance.
* (http://stackoverflow.com/questions/1093918/findall-not-returning-correct-object-type)
**/
class AutoFormTagLib {
def autoForm = {attrs, body ->
//def masterList = Class.forName(params.attrs.masterClass,false,Thread.currentThread().contextClassLoader).get(params.attrs.masterId)
def theItem = Item.get(attrs.itemId)
def theCollection = Metacollection.get(attrs.collectionId)
def masterList = theCollection.metadataSet.setTagtypes
def theParams = null
def theTags = null
def itemTag = null
def tag = null
masterList.each {
theParams = [attrs.itemId.toLong(),it.tagtype.id]
theTags = ItemTag.findAll("from ItemTag d, Item c, Tag b, Tagtype a where d.item = c and d.tag = b and b.tagtype = a and c.id=? and a.id=?",theParams)
for (int i=0;i<it.maxEntries;i++) {
out << "<tr>\n"
out << " <td>${it.tagtype.tagtype}</td>\n"
out << " <td>\n"
if (theTags[i]) {
itemTag = (ItemTag) theTags[i][0]
//item = (Item) theTags[i][1]
tag = (Tag) theTags[i][2]
//itemTag = (Tagtype) theTags[i][3]
out << " <input name='${it.tagtype.tagtype}_${i}_${itemTag.id}' value='${tag.tag}' />\n";
}
else
out << " <input name='${it.tagtype.tagtype}_${i}' />\n";
out << " </td>\n"
out << "</tr>\n"
}
}
}
}