- 浏览: 62519 次
- 性别:
- 来自: 福州
文章分类
最新评论
-
xpjava:
大侠您好! 我在使用easyui 的时候发现 他与grails ...
100%拿来主义——基于EasyUI和Grails的应用"框架"?! -
热带翎羽:
alanland 写道已经两年没更新了?有更新啦,公司行为,不 ...
基于Grails 1.3.7和extjs 3.4.0的模板框架(附源代码) -
热带翎羽:
alanland 写道这个不应该用国际化来做吗国际化可以实现, ...
Grails的Controller中如何获取Domain模型 -
alanland:
这个不应该用国际化来做吗
Grails的Controller中如何获取Domain模型 -
alanland:
已经两年没更新了?
基于Grails 1.3.7和extjs 3.4.0的模板框架(附源代码)
功能:根据Domain定义自动生成CRUD
效果图:
代码:
效果图:
代码:
<% import grails.persistence.Event %><% import org.codehaus.groovy.grails.plugins.PluginManagerHolder %><%=packageName%> <% boolean hasHibernate = PluginManagerHolder.pluginManager.hasGrailsPlugin('hibernate') %><% def output(p,cp) { if (p.type == String.class) { out << ",xtype: 'textfield'" if (cp.blank == false) { out << ", allowBlank: false, blankText: '\${cgDomainProperties.${p.name}.chinese}为必填项'" //,msgTarget: 'side'" } if (cp.maxSize != null) { out << ", maxLength: ${cp.maxSize}, maxLengthText: '\${cgDomainProperties.${p.name}.chinese}至多包含${cp.maxSize}个字符'" } if (cp.minSize != null) { out << ", minLength: ${cp.minSize}, minLengthText: '\${cgDomainProperties.${p.name}.chinese}至少包含${cp.minSize}个字符'" } } else if (p.type == Date.class) { out << "'datefield',format:'Y-m-d'" } } %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <g:extjs /> <g:set var="entityName" value="\${cgDomainProperties.cgChinese}" /> <title><g:message code="\${entityName}管理" /></title> </head> <script> Ext.onReady(function(){ Ext.QuickTips.init(); var ${domainClass.propertyName}CreateForm = new Ext.form.FormPanel({ labelAlign: 'right', labelWidth: 80, frame: true, url: '/foundation/${domainClass.propertyName}/createJSON', defaultType: 'textfield', items: [ {fieldLabel:'id',name: 'id',xtype: 'numberfield',hidden:true,hideLabel:true},<% excludedProps = Event.allEvents.toList() << 'version' << 'id' << 'dateCreated' << 'lastUpdated' persistentPropNames = domainClass.persistentProperties*.name props = domainClass.properties.findAll { persistentPropNames.contains(it.name) && !excludedProps.contains(it.name) } Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[])) display = true props.eachWithIndex { p, i -> if (!Collection.class.isAssignableFrom(p.type)) { if (hasHibernate) { cp = domainClass.constrainedProperties[p.name] display = (cp ? cp.display : true) } if (display) { %> {fieldLabel: '\${cgDomainProperties.${p.name}.chinese}',name: '${p.name}'<% output(p,cp) %>}<% if(props.size()>i+1){out<<","} %><% } } } %> ] }); var ${domainClass.propertyName}CreateWin = new Ext.Window({ el: '${domainClass.propertyName}CreateWin', closable:false, layout: 'fit', width: 400, title: '创建\${entityName}', height: 300, closeAction: 'hide', items: [${domainClass.propertyName}CreateForm], buttons: [{ text:'创建', handler: function(){ ${domainClass.propertyName}CreateForm.getForm().submit({ success:function(${domainClass.propertyName}CreateForm, action){ Ext.foundation.msg('信息', action.result.msg); ${domainClass.propertyName}CreateWin.hide(); store.reload(); }, failure:function(){ Ext.foundation.msg('错误', "创建\${entityName}失败!"); } }); } },{ text: '取 消', handler: function(){ ${domainClass.propertyName}CreateWin.hide(); } }] }); var ${domainClass.propertyName}UpdateForm = new Ext.form.FormPanel({ labelAlign: 'right', labelWidth: 80, frame: true, url: '/foundation/${domainClass.propertyName}/updateJSON', defaultType: 'textfield', items: [ {fieldLabel:'id',name: 'id',xtype: 'numberfield',hidden:true,hideLabel:true},<% excludedProps = Event.allEvents.toList() << 'version' << 'id' << 'dateCreated' << 'lastUpdated' persistentPropNames = domainClass.persistentProperties*.name props = domainClass.properties.findAll { persistentPropNames.contains(it.name) && !excludedProps.contains(it.name) } Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[])) display = true props.eachWithIndex { p, i -> if (!Collection.class.isAssignableFrom(p.type)) { if (hasHibernate) { cp = domainClass.constrainedProperties[p.name] display = (cp ? cp.display : true) } if (display) { %> {fieldLabel: '\${cgDomainProperties.${p.name}.chinese}',name: '${p.name}',xtype: <% if(p.type==String.class){ out << "'textfield'"} else if(p.type==Date.class){ out << "'datefield',format:'Y-m-d'"}%>}<% if(props.size()>i+1){out<<","} %><% } } } %> ] }); var ${domainClass.propertyName}UpdateWin = new Ext.Window({ el: '${domainClass.propertyName}UpdateWin', closable:false, layout: 'fit', width: 400, title: '修改\${entityName}', height: 300, closeAction: 'hide', items: [${domainClass.propertyName}UpdateForm], buttons: [{ text:'更新', handler: function(){ ${domainClass.propertyName}UpdateForm.getForm().submit({ success:function(${domainClass.propertyName}UpdateForm, action){ Ext.foundation.msg('信息', action.result.msg); ${domainClass.propertyName}UpdateWin.hide(); store.reload(); }, failure:function(){ Ext.foundation.msg('错误', "更新\${entityName}失败!"); } }); } },{ text: '取 消', handler: function(){ ${domainClass.propertyName}UpdateWin.hide(); } }] }); var ${domainClass.propertyName}DetailForm = new Ext.form.FormPanel({ labelAlign: 'right', labelWidth: 80, frame: true, url: '/foundation/${domainClass.propertyName}/detailJSON', defaultType: 'textfield', items: [ {fieldLabel:'id',name: 'id',xtype: 'numberfield',hidden:true,hideLabel:true},<% excludedProps = Event.allEvents.toList() << 'version' << 'id' persistentPropNames = domainClass.persistentProperties*.name props = domainClass.properties.findAll { persistentPropNames.contains(it.name) && !excludedProps.contains(it.name) } Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[])) display = true props.eachWithIndex { p, i -> if (!Collection.class.isAssignableFrom(p.type)) { if (hasHibernate) { cp = domainClass.constrainedProperties[p.name] display = (cp ? cp.display : true) } if (display) { %> {fieldLabel: '\${cgDomainProperties.${p.name}.chinese}',name: '${p.name}',readOnly: true, xtype: <% if(p.type==String.class){ out << "'textfield'"} else if(p.type==Date.class){ out << "'datefield',format:'Y-m-d'"}%>}<% if(props.size()>i+1){out<<","} %><% } } } %> ] }); var ${domainClass.propertyName}DetailWin = new Ext.Window({ el: '${domainClass.propertyName}DetailWin', closable:false, layout: 'fit', width: 400, title: '\${entityName}明细', height: 300, closeAction: 'hide', items: [${domainClass.propertyName}DetailForm], buttons: [{ text: '确定', handler: function(){ ${domainClass.propertyName}DetailWin.hide(); } }] }); var tb = new Ext.Toolbar(); tb.render('toolbar'); tb.add({ text: '新建', icon: '/foundation/images/skin/database_add.png', handler:function(){ ${domainClass.propertyName}CreateWin.show(this); } },{ text: '修改', icon: '/foundation/images/skin/database_edit.png', handler: function(){ var id = (grid.getSelectionModel().getSelected()).id; ${domainClass.propertyName}UpdateForm.getForm().load({ url:'/foundation/${domainClass.propertyName}/detailJSON?id='+id, success:function(form,action){}, failure:function(){ Ext.foundation.msg('错误', "服务器出现错误,稍后再试!"); } }); customerUpdateWin.show(); } },{ text: '删除', icon: '/foundation/images/skin/database_delete.png', handler: function(){ var count=sm.getCount(); if(count==0) { Ext.foundation.msg('注意', "请选择要删除的记录"); }else { var records = sm.getSelections(); var id=[]; for(var i=0;i<count;i++) { id.push(records[i].id); } Ext.MessageBox.confirm('信息', '您确定删除' + id + '记录?', function(btn) { if (btn == 'yes') { Ext.Ajax.request({ url: '/foundation/${domainClass.propertyName}/deleteJSON', params: {id:id}, success: function(result) { var json_str = Ext.util.JSON.decode(result.responseText); //Ext.foundation.msg('信息', json_str.msg); MessageShow('信息',json_str.msg); store.reload(); }, failure:function() { Ext.foundation.msg('错误', '服务器出现错误,稍后再试!'); } }); } }); } } },{ text: '详细', icon: '/foundation/images/skin/database_save.png', handler: function(){ var id = (grid.getSelectionModel().getSelected()).id; ${domainClass.propertyName}DetailForm.getForm().load({ url:'/foundation/${domainClass.propertyName}/detailJSON?id='+id, success:function(form,action){}, failure:function(){ Ext.foundation.msg('错误', '服务器出现错误,稍后再试!'); } }); customerDetailWin.show(); } },'->', { xtype: 'textfield', name: 'searchBar', emptyText: '请输入搜索条件' },{ text: '搜索', icon: '/foundation/images/skin/database_search.png', handler: function(){ } } ); tb.doLayout(); var sm= new Ext.grid.CheckboxSelectionModel() var cm = new Ext.grid.ColumnModel([ sm,<% excludedProps = Event.allEvents.toList() << 'version' allowedNames = domainClass.persistentProperties*.name << 'id' << 'dateCreated' << 'lastUpdated' props = domainClass.properties.findAll { allowedNames.contains(it.name) && !excludedProps.contains(it.name) && !Collection.isAssignableFrom(it.type) } Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[])) props.eachWithIndex { p, i -> if (i < 10) { if (p.isAssociation()) { %><% } else { %> {header:'\${cgDomainProperties.${p.name}.chinese}',dataIndex:'${p.name}'} <% if(props.size()>i+1){out<<","} %><% } } } %> ]); var store= new Ext.data.Store({ autoLoad:true, proxy: new Ext.data.HttpProxy({url:'/foundation/${domainClass.propertyName}/listJSON'}), reader: new Ext.data.JsonReader({ totalProperty:'total', root:'root' },[<% props.eachWithIndex { p, i -> if (i < 10) { if (p.isAssociation()) { %><% } else { %> {name:'${p.name}'}<% if(props.size()>i+1){out<<","} %><% } } } %> ]) }); var grid= new Ext.grid.GridPanel({ renderTo: 'grid', store: store, enableColumnMove:false, enableColumnResize:true, stripeRows:true, enableHdMenu: false, trackMouseOver: true, loadMask:true, cm: cm, sm: sm, height: 270, viewConfig: { forceFit:true }, bbar: new Ext.PagingToolbar({ pageSize: 10, store: store, displayInfo: true, displayMsg: '显示第{0}条到第{1}条记录, 共{2}条', emptyMsg: '没有记录' }) }); store.load({params:{start:0,limit:10}}); var window = new Ext.Window({ // contentEl : Ext.getBody(), id: 'msgWindow', width : 200, height : 150, shadow : false, html : "试试试试...", title : "温馨提示:" }); function show() { this.el.alignTo(Ext.getBody(), 't'); this.el.slideIn('t', { easing : 'easeOut', callback : function() { this.close.defer(1000, this); //定时关闭窗口 }, scope : this, duration : 1 }); } function hide() { if (this.isClose === true) { //防止点击关闭和定时关闭处理 return false; } this.isClose = true; this.el.slideOut('t', { easing : 'easeOut', callback : function() { this.un('beforeclose', hide, this); this.close(); }, scope : this, duration : 1 }); return false; } window.on('show', show, window); window.on('beforeclose', hide, window) //window.show(); function MessageShow(title, content) { var win = Ext.getCmp('msgWindow'); win.setTitle(title); //win.html=content; win.show(); } }); </script> <body> <div id="toolbar"></div> <div id="grid"></div> <div id="${domainClass.propertyName}CreateWin"></div> <div id="${domainClass.propertyName}UpdateWin"></div> <div id="${domainClass.propertyName}DetailWin"></div> </body> </html>
相关推荐
将Grails与JQuery集成起来
NULL 博文链接:https://search.iteye.com/blog/383347
NULL 博文链接:https://zeroblue.iteye.com/blog/1158924
grails jobs 定时任务 项目demo
供初学者使用,在grails中只有list(自动生成)中有分页实现,而自己新增的页面中需自己实现分页,该文档中描述了如何实现分页以及注意点
Grails Grails Grails Grails Grails
MongoDB Grails插件 MongoDB Grails插件主要作为称为“ mongo”的Spring bean公开给Grails应用程序。 然后,只需添加“ mongo”,Grails类就可以轻松地在整个代码中使用它。 支持依赖注入(域/控制器/服务)的类的...
11.2 通过集成hibernate实现orm 11.2.1 使用hibernatecxml映射 11.2.2 ejb3方式的映射 11.2.3 在pojo实体中使用约束 11.2.4 得到sessionfactory对象 11.3 使用spring进行依赖注入 ...
Grails视频教程:A screencast that demonstrates Grails' scaffolding feature
Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南Grails权威指南
grails-脚手架-extjs Grails 插件,用于使用 ExtJS 前端和 REST 后端生成工作演示。 创建演示 需要覆盖脚手架配置:添加到 Config.groovy grails.plugin.scaffold.core.folders = ['backend':'', 'frontendExtjs':...
本文主要介绍Grails和Maven集成。Grails2.1版本以后,对Maven的集成有了很大的改进。本文通过实例讲述Grails与Maven集成的各种方法,使读者可以学会使用Maven对Grails项目进行构建。Grails简介:Grails是一个开源的...
First-time developers are amazed at how quickly you can get a page-centric MVC web site up and running thanks to the scaffolding and convention over configuration that Grails provides. Advanced web ...
A tutorial showing how do develop a Grails application with a GWT UI. Prepare your system The first step is to set up your system for running Grails and the GWT. You will also need to create a new ...
NULL 博文链接:https://extrimlycold20070206121610.iteye.com/blog/1139647
Grails入门好资料
详细说明Garils项目中集成GWT配置使用情况!
如何为了充分理解用本项目实现的不同案例之间的关系,建议按以下方式使用: 通过更改Config.groovy的选项来试验不同的可用客户端模式域此应用程序中的域尝试广泛使用插件提供的映射选项。 要查找特定映射,请参阅...
使用GORM构建Spring Boot应用程序 Grails指南_ Grails框架.pdf
Grails项目的应用越来越多,而对于初学者来说,在Eclipse下搭建Grails项目是一个难题,这个文档将教会你如何搭建Grails项目,希望对你有所帮助。