我可以在Grails1中这样做吗:动态创建数据输入表单

我可以在Grails1中这样做吗:动态创建数据输入表单,grails,Grails,我正在考虑在我当前的项目中使用Grails。我有几个要求,我希望我能在Grails中做到 首先,我有以下数据库表: TagType --------- tag_type_id tag_type Sample Data: TagType -------------------- 1,title 2,author 基于这些数据,我需要生成这样的数据输入表单 将其数据保存到另一个表中 瓷砖_ 作者 保存取消 我可以在Grails中这样做吗?你能给我指一下正确的方向吗 谢谢 更多细节 我正在构

我正在考虑在我当前的项目中使用Grails。我有几个要求,我希望我能在Grails中做到

首先,我有以下数据库表:

TagType
---------
tag_type_id
tag_type


Sample Data: TagType
--------------------
1,title
2,author
基于这些数据,我需要生成这样的数据输入表单 将其数据保存到另一个表中

瓷砖_
作者
保存取消

我可以在Grails中这样做吗?你能给我指一下正确的方向吗

谢谢

更多细节 我正在构建一个支持OIA-PMH的数字图书馆系统,OIA-PMH是共享文档元数据的标准。该标准规定,每个元素都是可选的和可重复的。为了支持这个需求,我有以下数据库设计

我需要主要基于内容生成用户GUI(数据输入表单) 标记类型表(见上文)。表单中的数据将保存到 标签(如果标签是新的)和项目标签表

Items
---------
item_id
last_update

Tags
--------
tag_id
tag_type_id
tag

TagType
---------
tag_type_id
tag_type

Item_tags
---------
item_id
tag_id

Sample Data: Items
------------------
1,2009-06-15

Sample Data: TagType
--------------------
1,title
2,author

Sample Data: Tags
------------------

1,1,The Definitive Guide to Grails
2,2,Graeme Rocher
3,2, Jeff Brown

Sample Data: Item_tags
-----------------------
1,1
1,2
1,3

关于“将其数据保存到另一个表”,我不能完全确定您在这里要求什么,但这里有一些想法

对于您拥有的表,您需要的域类如下所示:

类标签{ 字符串类型

}

ID字段将在创建脚手架时自动生成

如果这还不够,请在您的问题中添加更多信息

我真的很喜欢圣杯。当我几周前第一次开始使用它时,我没有意识到它是一种成熟的语言。事实上还不止这些。它是一个完整的web堆栈,包含一个web服务器和一个数据库。总之,我的问题的简短答案是肯定的。当然,你甚至可以说是的!以下是我创建的标记库的代码:

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"
            }
        }

    }
}
import org.maflt.flashlit.pojo.Item
导入org.maflt.flashlit.pojo.ItemTag
导入org.maflt.flashlit.pojo.Metacollection
导入org.maflt.flashlit.pojo.SetTagtype
导入org.maflt.flashlit.pojo.Tag
导入org.maflt.flashlit.pojo.Tagtype
/**
*@返回给定集合的元数据集中所有字段的输入表单字段。如果TagType不在Metadataset中,则不返回ItemTags。
*  
*在冬眠状态下
*
*“从ItemTag b,标记a,其中b.Tag=a”
*
*查询是交叉连接。此查询的结果是一个对象数组列表,其中第一项是ItemTag实例,第二项是Tag实例。
*
*你必须使用。
*
*(ItemTag)标签2[0][0]
*
*访问第一个ItemTag实例。
* (http://stackoverflow.com/questions/1093918/findall-not-returning-correct-object-type)
**/
类AutoFormTagLib{
def autoForm={attrs,body->
//def masterList=Class.forName(params.attrs.masterClass,false,Thread.currentThread().contextClassLoader).get(params.attrs.masterId)
def-Item=Item.get(attrs.itemId)
def theCollection=Metacollection.get(attrs.collectionId)
def主列表=collection.metadataSet.setTagtypes
def theParams=null
def theTags=null
def itemTag=null
def标记=null
主列表。每个{
参数=[attrs.itemId.toLong(),it.tagtype.id]
tags=ItemTag.findAll(“来自ItemTag d,Item c,Tag b,Tagtype a,其中d.Item=c和d.Tag=b,b.Tagtype=a和c.id=?和a.id=?”,参数)
对于(int i=0;i