I am new to grails and I have a question about limiting a query result: domain User:
my GSP page snippet that displays the results:Code:class User { String login String password String fname String lname String role = "user" static constraints = { login (size:5..15, blank:false, unique:true,matches:"[a-zA-Z0-9]+") password (size:5..15, blank:false) fname (blank:false) lname (blank:false) role(inList:["user", "admin"]) } String toString(){ fname & " " & lname } static mapping = { cache true columns { fname type:'text' lname type: 'text' password type:'text' login type:'text' } } }
I call the controller with this code, in separate gsp view:Code:<g:each in="${userInstanceList}" status="i" var="userInstance"> <tr class="${(i % 2) == 0 ? 'odd' : 'even'}"> <td><g:link action="show" id="${userInstance.id}"> ${fieldValue(bean: userInstance, field: "id")} </g:link></td> <td>${fieldValue(bean: userInstance, field: "login")}</td> <td>****</td> <td>${fieldValue(bean: userInstance, field: "fname")}</td> <td>${fieldValue(bean: userInstance, field: "lname")}</td> <td>${fieldValue(bean: userInstance, field: "role")}</td> </tr> </g:each>
My question is, how do I call the domain and display the results according to the following criteria: first, if the Role is admin, display everything. If the role is not admin, only display the results of certain login value (ie, just show the results where the login = the current user)Code:<g:link class="users" controller="user" params="[sort:'fname',order:'desc']" action="" >Manager Users</g:link>
Thanks for your help! jason


Reply With Quote