我有這樣的控制器:Grails的控制器簡單的問題
def participated = {
def user = User.get(1)
def temp = ConferenceUser.findAllByUser(user)
def prizes = Prizes.list()
[temp: temp, prizes: prizes]
//redirect(action: "participated", params: params)
}
這GSP觀點:
<g:each in="${temp}">
<li>Date: ${it.dateParticipated}, <br>Role: ${it.role}, <br>Acceptence: ${it.accepted}, <br>
<g:link controller="conference" action="participated" params="[temp: it.conference.id]">
Conference: </g:link>${it.conference},<br>
Status: ${it.status}</li><br>
<g:each in="${prizes.findAllByConferenceUser(temp.id)}"> ########
PrizeName: ${it.name}
</g:each>
<br>
</g:each>
我想要做的是,印刷我需要的所有conferenceUser對象後,我需要打印以該會議用戶ID贏得的所有獎品。 ##在哪裏,是我的問題。我不知道如何在控制器中做到這一點,因爲'臨時'給了我所有由用戶過濾的會議用戶。但我也需要贏得conferenceUSer ID過濾的所有獎品。所以我通過了控制器temp(代表所有與用戶id = 1的會議)並且我通過了所有獲勝的獎品,以便在第二個'each'標籤中對它們進行過濾。但是這種方式不起作用,因爲,就像我現在一樣,temp.id表示多個ID(如錯誤所示)。請幫忙嗎?我怎樣才能得到當時在第一個標籤中使用的ID?
Error 500: Error evaluating expression [prizes.findAllByConferenceUser(temp.id)] on line [44]: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.findAllByConferenceUser() is applicable for argument types: (java.util.ArrayList) values: [[50, 51, 52, 53, 54, 55, 57]]
Servlet: grails
URI: /CM/grails/conferenceUser/participated.dispatch
Exception Message: No signature of method: java.util.ArrayList.findAllByConferenceUser() is applicable for argument types: (java.util.ArrayList) values: [[50, 51, 52, 53, 54, 55, 57]]
Caused by: Error evaluating expression [prizes.findAllByConferenceUser(temp.id)] on line [44]: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.findAllByConferenceUser() is applicable for argument types: (java.util.ArrayList) values: [[50, 51, 52, 53, 54, 55, 57]]
Code Snippet:
對此感謝答案。但是,那麼,如果它是控制器中的渲染器,我該如何格式化該數據? – robert 2011-05-22 23:06:01
@robert即時通訊不是說從控制器呈現數據,即時通訊說不要從一個gsp做findAllByConferenceUser。按照您希望的方式在控制器上設置數據,然後將其傳遞給gsp。基本上gsp應該儘可能愚蠢。 – hvgotcodes 2011-05-22 23:09:53
好的。謝謝你的幫助。 – robert 2011-05-22 23:16:56