Grails g:if and string comparison

16,847

Solution 1

try "java" String ways :D

<g:if test="${session.userPermissions.equals('Administrator')}">
....
</g:if>

Solution 2

It ends up a groovy thing-

I used a criteria to get the user's login information. The criteria returns a list of user variables. I was setting session.userPermissions = user.permissions

In groovy you can access every list element's properties and retrieve them as a new list (example below). This was giving me the list variables in my session. It's a really cool feature, but not one you like to find on accident like this.

groovy> def demo = []
groovy> demo[0] = [a:1, b:2]
groovy> demo[1] = [a:3, b:4]
groovy> demo[2] = [a:5, b:6]
groovy> demo.a

Result: [1, 3, 5]
Share:
16,847
Noaki
Author by

Noaki

Updated on June 28, 2022

Comments

  • Noaki
    Noaki almost 2 years

    I've written some code that checks to see if the user is logged in as an admin or not to limit who can make changes to other user's permissions, but the if tag is never true. I've made sure the correct data is there by echoing it out but nothing I've found so far has given me a solution.

    <g:if test="${session.userPermissions == 'Administrator'}">
        <g:select id="permissions" name="permissions" from="${userInstance.constraints.permissions.inList}" value="${userInstance.permissions}" ></g:select>
    </g:if>
    <g:else>
        ${userInstance.permissions}
    </g:else>