You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 18 Members of 4546 |
| Forum: Seam Users |
28. Jul 2008, 16:22 CET | Link |
I have a problem ending a conversation. I have a dataTable, there is a link for each column. If a user clicks on a link the current object will be put into conversation scope, a long running conversation will be started and the user will be forwarded (no redirect) to a new page. Additional objects and collections will be put in the conversation on the detail pages.
Here's the problem: When the user goes back to the overview page (which contains the dataTable) and clicks the above mentioned link for another row, the current conversation must be ended (if one exists) and a new one needs to be started. I am using the following code snipped in the action method for that link but the code does not work as expected. The old objects and collections still remain in the same conversation. Here's the code:
if (Conversation.instance().isLongRunning()) {
Conversation.instance().end();
Conversation.instance().begin(false, false);
} else {
Conversation.instance().begin();
}
I created a test case where I called the end() method in a separate request, the conversation will be destroyed and all objects were removed. Why does that not work for one request? What is wrong with my understanding / code? Have I forgot something?
Thanks in advance!
Anyone can help?
Hmm, I managed to sneak errors into my text already. You can end the conversation before a redirect if you use @End(beforeRedirect=true)
There is always a conversation present, and it can be temporary or long-running.
If the conversation is long-running, which can be set by using @Begin, the context gets propagated to the next request of the same user (session). If not (temporary conversation), the context will be destroyed when the request ends. @End merely tells Seam to demote the conversation to temporary.
A conversation context will not be destroyed during a request, because the context has the same life-span as a request (in practice it is bound to the current thread as a ThreadLocal).
There is lots and lots of documentation on this. Read the docs.
Looks a bit like my problem.
I use the EntityHome on the new page - as created by JBoss Tools - New Entity.
When a user clicks on the menu for the list, then clicks on one of the rows to edit, then clicks on the menu to see the list again, and clicks on another row to edit, the first row is visible.
To avoid this problem, so the new row to edit is edited, I changed the RequestParameter in the home object:
@RequestParameter public void setMdaIcnMonthsId(Long mdaIcnMonthsId) { if (mdaIcnMonthsId != null) if (this.getConversation().isLongRunning()) if (this.instance != null) if (this.instance.getKey() != null) if (this.instance.getKey().compareTo(mdaIcnMonthsId) != 0 ) { this.instance = getEntityManager().find(MdaIcnMonths.class, mdaIcnMonthsId); } this.mdaIcnMonthsId = mdaIcnMonthsId; }But this seems to me a bit wrong. Is it, or what should I do. Have not found an answer on forum or book...
read this
Thanks, I am reading this.
But I can not find the answer...
The example I use was created by Seam - Create new entity. A list object and a home object together with the xhtml-pages is created. The standard behaviour is as I stated:
In the example use is made of an action method to select the correct object. I am looking for something to use this option and work with the correct object.
The code I am using here does the trick, but I think it is nasty to do it like this.
I used a workaround to avoid these problem in my code. I thought that when I stop a conversation with @End or programatically with Conversation.instance().end(); that all objects stored in that conversation will be destroyed. Unfortunately, that is only true if I do no start a new conversation within the same request (no redirect). Or isn't it?
Currently I am using
so there is no need to end the current conversation and start a new one but all existing objects won't be destroyed. Is there a solution to destroy all objects in a conversation?