【发布时间】:2013-07-05 18:30:58
【问题描述】:
我是 Grails 的新手。我使用Spring Security Grails plugin 进行身份验证。我想在我的视图 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 ......
请帮忙。
【问题讨论】:
标签: grails spring-security grails-2.0 gsp