简体   繁体   中英

grails how to output message in tag lib

I'm trying to pull in a message from message.properties from a taglib, but the output is empty. I know the taglib is being called because if I output out << 'hello' it works fine. And my code is defined because if I change the codename to something that doesn't exist in the properties file my IDE highlights the code with red text, indicating it wasn't found.

class AccountTagLib {

    def accountType = { attrs, body ->
                out << message(code: 'account.friendlyType.BF')
}
}

message.properties:

account.friendlyType.BF=Here I am

I think it should work like

out << g.message(code: 'account.friendlyType.BF')

At least that is how I always use it (successfully). But I also read that you can omit the namespace for builtin taglibs (see answer Can I use grails tag outside of GSP? ) so that yours should work too. If it does not work as I proposed may be the other answers to that question Can I use grails tag outside of GSP? help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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