Reputation: 2850
I have a domain User, that hasMany queues. Adding and displaying queues works ok, but when i delete a queue from a user, the queue is deleted, but is still displayed in the browser. The view is refreshed only when i logout and login again.
Where i remove them:
def user = session?.user
def queue = Queue.findById(params.queueId)
if(queue){
user.removeFromQueues(queue)
queue.delete(flush:true)
flash.message = "deleted queue with id: ${queue.id}"
redirect(controller:'queue', action:'index')
}
And is displayed in such a way:
<g:each in="${session?.user?.queues}">
<div id="queue">
${it.name} id:${it.id}
<div id='queueButtons'>
<g:hiddenField name="queueId" value="${it.id}" />
<g:link controller='queue' action='delete' params="[queueId: "${it.id}"]">X</g:link>
</div>
</div>
</g:each>
Why the user is not refreshed? When i add a queue to user, it is displayed immediately. Is there a way to refresh the user/session?
Upvotes: 0
Views: 582
Reputation: 24776
As stated in the comments, keeping a user domain instance in the session is not only is it a very bad idea it's the cause of your issue.
Your user instance in the session isn't attached to the hibernate session so it's not being updated.
Redesign/Refactor your code to keep only the bare minimum of information in the session (user id is a good idea) and go from there. You are causing more problems for yourself than you are solving by trying to put too much into the session and things are only going to get worse if you continue down that path.
Upvotes: 1