grails - 没有为自定义操作调用Grails筛选器

标签 grails filter grails-filters

我正在尝试实现一个过滤器,该过滤器在转到GSP页面之前应在某些情况下调用。由于URL在我希望发生的实例与我不希望发生的实例之间没有太大差异,因此我认为做到这一点的最佳方法是创建一个不执行任何操作的方法(内部带有打印语句) -但当我希望执行过滤操作时可以简单地调用它。

我已经尝试过这两个:

def hello(){
    print "hello"       
}


def hello = {
    print "hello"
}

通过添加简单地调用这些
hello()

在相关点

我的过滤器的开始如下:
import uui.FormattingService

class TimeFormatterFilters {

    def FormattingService formattingService

    def filters = {
        someFilter(controller: 'userProfile', action: 'hello') {
            before = {
                print "filter action taking place"

我没有看到UserProfileController中两个新创建的方法从过滤器中看到的print语句,但是如果我将过滤器的操作交换为'index',则会看到过滤器中的打印被调用。

最佳答案

您面临的问题是您正在直接从 Controller 中的另一个 Action 调用hello() Action 。这只是一个普通的方法调用,不会通过过滤器。

当HTTP客户端请求特定URI(例如, http://localhost:8080/my-app/myController/myAction将匹配myControllermyAction

如果您仅在响应其他URI时从 Controller 内部调用myAction(),则不会使用该过滤器。你在做什么

关于grails - 没有为自定义操作调用Grails筛选器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30305956/

相关文章:

mongodb - 如何在Grails中为MongoDB设置readPreference

mongodb - 无法获取 grails 中关联字段的 dirtyPropertyNames 属性值

grails - Grails生成 View 运行两次

google-apps-script - 向数据透视表添加过滤器

filter - 具有数组值的 Algolia 分面过滤器

security - Grails 安全过滤除一项之外的所有操作

mongodb - 由于 grails-datastore-gorm-plugin-support :jar:3. 1.3.BUILD-SNAPSHOT,Hudson 中的构建失败不一致

git 查找被 smudge/clean 过滤器过滤的文件的文件名

grails - Grails过滤器 `actionExclude`是否可用于基于方法的路由?

regex - Grails过滤器正则表达式