【问题标题】:Grails 2.5.0 - Setting up JQGrid on fresh Grails installGrails 2.5.0 - 在新安装的 Grails 上设置 JQGrid
【发布时间】:2015-07-17 19:11:19
【问题描述】:

我已经完成的步骤:

  1. 创建新项目
  2. mavenRepo "http://repo.grails.org/grails/core" 添加到 BuildConfig.groovy 中的存储库
  3. 在 BuildConfig.groovy 的插件中添加 compile ":easygrid:1.7.1"
  4. 使用String firstnameString lastname 添加域类com.test.Author
  5. def index() { }添加控制器com.test.HomeController
  6. 添加文件views/home/index.gsp

接下来,我在 com.test.HomeController 中添加了以下内容: def authorJQGrid = { domainClass Author gridImpl 'jqgrid' jqgrid { sortname 'firstname' } export { export_title 'Author' pdf { 'border.color' java.awt.Color.BLUE } } columns { firstname lastname } }

我在 home/index.gsp 中添加了以下内容:

<!DOCTYPE html> <html> <head> <asset:javascript src="easygrid.jqgrid.js"/> <asset:stylesheet src="easygrid.jqgrid.css"/> </head> <body> <grid:grid id='jqgridinitial' name='authorJQGrid'> <grid:set width="900" caption="Authors"/> </grid:grid> <grid:exportButton name='authorJQGrid'/> </body> </html>

当我编译这个时,我看到以下错误:

Could not process the EasygridConfig file

当我尝试访问网页时,我收到以下错误:

[http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - 处理请求时发生 NullPointerException:[GET] /website/home/ 无法在空对象上获取属性“authorJQGrid”。堆栈跟踪如下: 消息:处理 GroovyPageView 时出错:执行标签时出错:无法在空对象上获取属性“authorJQGrid”

我该怎么做才能让 JQGrid 正常工作?

【问题讨论】:

  • 您是否使用 @Easygrid 注释了您的 Controller 类?
  • 那是我的问题。谢谢!

标签: grails jqgrid


【解决方案1】:

为了使用插件 EasyGrid,控制器(定义网格的地方)必须用 @Easygrid 注释。

下面的例子,摘自https://github.com/tudor-malene/grails-petclinic/blob/master/grails-app/controllers/org/grails/samples/OverviewController.groovy,展示了一个例子:

@Easygrid
class OverviewController {

    def ownersGrid = {
        domainClass Owner
        columns {
            id {
              type 'id'
              enableFilter false
            }
            firstName
            lastName
            address
            city
            telephone
            nrPets {
            enableFilter false
            value { owner ->
                owner.pets.size()
            }
            jqgrid {
                sortable false
            }
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-29
    • 2012-07-11
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 2015-08-11
    相关资源
    最近更新 更多