views:

160

answers:

1

I have a grails tag library TpTagLib and in it I want to define 4 new tags that differ only in one constant value, so I tried to use curry. But there is an exception: groovy.lang.MissingPropertyException: No such property: attr for class: TpTagLib

Does anyone have any idea why this exception occurs? Here is the code:

def ifPermsTag = { permissions, attr, body ->
    def user = attr?.user ?: session.userInstance
    if( !user ) return false
    if( !securityService.hasPermissions(user,permissions) ) return false
     out << body()
    return true
}


def canAdminRequestmaps = ifPermsTag.curry(Permission.CAN_ADMIN_REQUESTMAPS)
def canAdminCorporations = ifPermsTag.curry(Permission.CAN_ADMIN_CORPS)
def canAdminUsers = ifPermsTag.curry(Permission.CAN_ADMIN_USERS)    
def canAdminDevices = ifPermsTag.curry(Permission.CAN_ADMIN_DEVICES)
+2  A: 

Cool technique. You just need to make ifPermsTag private so it's not considered a candidate to be a usable tag method:

private ifPermsTag = { permissions, attr, body ->
...
}

Tags can have no parameters, or an 'attr' parameter, or an 'attr' and 'body' parameters but other signatures are invalid.

Burt Beckwith
Since other signatures are invalid for a tag, I was actually counting on it not being seen as a tag, but private is a good way to make sure of that. Thanks.
Azder