gsp - Return Boolean value from Grails Tablib? -


this question has answer here:

i created custom grails tablib:

  def hasrole = { attrs, body ->     boolean result = false      if (attrs.roles) {       if (springsecurityutils.ifanygranted(attrs.roles)) {         result = true       }     }     out << result     } 

this can used this:

${cust.hasrole(roles:'role_admin') ? 'yes' : 'no' } 

the problem comparison alway results yes. seams expression not evaluated correctly.

the returning class type of hasrole org.codehaus.groovy.grails.web.util.streamcharbuffer.

how above expression evaluated correctly such hasrole() returns boolean value?

the key going use of returnobjectfortags in taglib. default tag library outputs information output writer (out). in case want this:

package example  class footaglib {   static namespace = 'something'   static returnobjectfortags = ['hasrole']    def hasrole = { attrs, body ->     boolean result = false     ...     return result   } } 

as can see returnobjectfortags static list of methods/closures want return actual objects , don't expect modifying output stream directly.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -