Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用Grails安全ACL筛选选择下拉列表_Spring_Security_Grails_Acl - Fatal编程技术网

Spring 使用Grails安全ACL筛选选择下拉列表

Spring 使用Grails安全ACL筛选选择下拉列表,spring,security,grails,acl,Spring,Security,Grails,Acl,我正在使用SpringSecurityACL插件实现ACL安全性。我有以下域类: package test class Subitem { String name static belongsTo = [employer: Employer] static constraints = { name blank: false } } package test class Employer { String name static hasMany

我正在使用SpringSecurityACL插件实现ACL安全性。我有以下域类:

package test
class Subitem {

   String name

   static belongsTo = [employer: Employer]

   static constraints = {
    name blank: false
   }
}

package test
class Employer {
   String name

   static hasMany = [users: User, items: Subitem]
   static belongsTo = User

   static constraints = {
    name blank: false, unique: true
   }

   String toString() {
    name
   }
}
在用于创建子项的create.gsp文件中,有以下语句:

<g:select id="employer" name="employer.id" from="${test.Employer.list()}" optionKey="id" required="" value="${subitemInstance?.employer?.id}" class="many-to-one"/>
在给出的教程之后,我将与雇主打交道的一些功能移到了一个名为EmployeerService的服务中:

@PreAuthorize("hasRole('ROLE_USER')")
@PostFilter("hasPermission(filterObject, read)")
List<Employer> list(Map params) {
   Employer.list params
}
int count() {
   Employer.count()
}
我只想查看来自EmployerService list()函数的信息-我该怎么做?如何从间隙中引用正确的功能

  • 编辑3月16日0835:Thank@Over热心,这真的很有帮助,我没有意识到这一点。然而,我试过了,仍然遇到同样的问题。我在Employer和EmployerService list()函数中都添加了println()语句,可以看出在解析g:select标记时,这两个函数似乎都没有被调用(即使我将g:select留给Employer)。是否有正在调用的list()函数的另一个版本?或者如何获得g:select以考虑ACL

只需更改服务中的方法签名,如下所示:

List<Employer> list(Map params = [:]) {
   Employer.list params
}
列表列表(映射参数=[:]){
雇主列表参数
}
更改添加了以下内容:
=[:]
。这为
params
提供了默认值,在本例中为空映射


(顺便说一句,这是Groovy的一项功能。您可以在参数可选的任何方法或闭包上使用它,并且您希望提供一个默认值。)

好的,我已经解决了它,下面是其他遇到相同问题的人的解决方案

创建子项页面通过子项的create.gsp文件和子项控制器呈现。诀窍是修改SubitemControllercreate()闭包:

class SubitemController {

def employerService

def create() {
    // this line was the default supplied method:
    // [subitemInstance: new Subitem(params)]
    // so replace with the following:
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    [subitemInstance: new Subitem(params), employerInstanceList: employerService.list(params),
     employerInstanceTotal: employerService.count()]
    }
}
因此,现在当g:select在雇主列表的子项视图中询问SubitemController时,它调用EmployeerService,它提供正确的答案。我们只添加了另外两个返回到视图的变量,这些变量可以在视图中的任何位置引用(例如通过g:select标记)


我从中得到的教训是,视图与控制器交互,控制器可以引用服务:服务似乎不能很好地与视图配合使用。

非常感谢,我不知道这一点!然而,这里似乎还有一个更深层次的问题,就是g:select如何调用list()函数——请参见上面我编辑的问题。
URI /security/subitem/create
Class groovy.lang.MissingMethodException
Message No signature of method: static test.EmployerService.list() is applicable for argument types: () values: [] Possible solutions: list(java.util.Map), is(java.lang.Object), wait(), find(), wait(long), get(long)
List<Employer> list(Map params = [:]) {
   Employer.list params
}
class SubitemController {

def employerService

def create() {
    // this line was the default supplied method:
    // [subitemInstance: new Subitem(params)]
    // so replace with the following:
    params.max = Math.min(params.max ? params.int('max') : 10, 100)
    [subitemInstance: new Subitem(params), employerInstanceList: employerService.list(params),
     employerInstanceTotal: employerService.count()]
    }
}