2014-01-22 35 views
0

每當我在我的template.gsp中調用<ut:profilePicture>時發生錯誤。這是我的customTagLib已經爲此響應調用Grails getWriter()

import rms.User 

class userTagLib { 
    def springSecurityService 
    static namespace = "ut" 

    def fullName = { 
     User currentUser = springSecurityService.currentUser as User 
     if (currentUser) { 
      out << currentUser.firstName + " " + currentUser.lastName 
     } 
    } 

    def profilePicture ={ 
     User currentUser = springSecurityService.currentUser as User 
     if (currentUser){ 
       response.outputStream << currentUser.picture 
     } 
    } 
} 

我需要發佈gsp代碼嗎?

回答

2

你在混合HTML和圖片。您不能只將二進制圖像放入HTML中,HTML應該只包含指向圖像的鏈接。

你可以做一個控制器與行動的個人資料圖片,如:

def picture() { 
    User user = User.get(params.id) 
    response.contentType = ... // image/jpeg i guess? 
    response.outputStream << user.picture 
    return null 
} 

,把一個標籤內的鏈接:

def profilePicture ={ 
    User currentUser = springSecurityService.currentUser as User 
    if (currentUser){ 
     out << '<img src="' 
     out << createLink(controller: 'user', action: 'profile', id: currentUser.id) 
     out << '" alt="" />' 
    } 
} 
+0

但不會,如果在GSP輸出鏈接使用的標籤並不會顯示實際的圖片? – Jan

+0

時間,你的意思是? –

+0

'createLink(controller:'user',action:'profile',id:currentUser.id)'我試過了,'createLink'被強調並且輸出是'/ myProject/admin/picture/2' – Jan

相關問題