我是Grails的新手。我正在使用Spring Security Grails 插件进行身份验证。我想在我的视图 gsp 文件中获取当前用户。
我正在尝试这样...
<g:if test="${post.author == Person.get(springSecurityService.principal.id).id }">
<g:link controller="post" action="edit" id="${post.id}">
Edit this post
</g:link>
</g:if>
在这里,我想仅显示由已登录用户创建的那些帖子的编辑此帖子链接。但它显示错误 -
Error 500: Internal Server Error
URI
/groovypublish/post/list
Class
java.lang.NullPointerException
Message
Cannot get property 'principal' on null object
这是我的 Post.groovy——
class Post {
static hasMany = [comments:Comment]
String title
String teaser
String content
Date lastUpdated
Boolean published = false
SortedSet comments
Person author
....... more code ....
这是我的 Person.groovy 域类文件——
class Person {
transient springSecurityService
String realName
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
byte[] avatar
String avatarType
static hasMany = [followed:Person, posts:Post]
static searchable = [only: 'realName']
........ more code ......
请帮忙。