繁体   English   中英

grails如何覆盖g消息标记

[英]grails how to override g message tag

我是Grails的新手,所以你可能会觉得我的问题很天真。 我想覆盖g消息标记。 我想在标记的行为中添加新功能,然后从ValidationTagLib调用原始实现。 就我而言,我可以创建自己的taglib,重新定义标签。 G message是一个实际上从ValidationTaglib调用messageImpl方法的闭包。 我的问题是如何调用此方法? 我尝试使用此代码来调用闭包,但是我收到了空格而不是消息:

class MyTagLib {

    static namespace = "g"

    def message = { attrs ->
        //my changes in tag's behaviour
        def validationTagLib = grailsAttributes.applicationContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib')
        validationTagLib.message.call(attrs)
    }
} 

我非常感谢你的帮助!

您需要扩展Grails ValidationTagLib

import org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib

class MyValidationTagLib extends ValidationTagLib {

    /**
     * Resolves a message code for a given error or code from the resource bundle.
     *
     * @emptyTag
     *
     * @attr error The error to resolve the message for. Used for built-in Grails messages.
     * @attr message The object to resolve the message for. Objects must implement org.springframework.context.MessageSourceResolvable.
     * @attr code The code to resolve the message for. Used for custom application messages.
     * @attr args A list of argument values to apply to the message, when code is used.
     * @attr default The default message to output if the error or code cannot be found in messages.properties.
     * @attr encodeAs The name of a codec to apply, i.e. HTML, JavaScript, URL etc
     * @attr locale override locale to use instead of the one detected
     */
    Closure message = { attrs ->
        //my changes in tag's behaviour
        ValidationTagLib validationTagLib = grailsAttributes.applicationContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.ValidationTagLib')
        validationTagLib.message.call(attrs)
    }
}

ils子

[英]Grails <g:set tag in javascript

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM