Argh! Where is the cid coming from?
krica Apr 7, 2007 4:21 AMHi,
While I really like Seam, sometimes it feels like I've just traded one set of problems for another, that being conversation propagation. Almost every non-trivial web page interaction causes some sort of problem for me.
Anyway, here's my current problem, and while I have found a workaround (which I'll show at the end), I simply cannot understand WHY I need to do that. The problem is that I get a "IllegalStateException: long-running conversation already active".
The application has a user type named Bidder. A bidder may submit one and only one bid to the system. A bid consists of one or more bid items, which are price/volume pairs. Bidders can always view their bid, and based on some business rules, the bidder may be able to edit the bid or request a bid correction (which is an edit with approval).
From the bidder's home page, he can choose ViewBid, and from ViewBid he can choose a link which directs him to ReqCorr (request correction). While in ReqCorr he can edit a DataTable and, most importantly for this discussion, he can CANCEL his edit.
ViewBid is managed by bidderViewBidManager (Stateful, CONVERSATION) but (in this use case) does not start or end any conversations. ReqCof is managed by bidderBidCorrectionManager (also Stateful, CONVERSATION). This conversation is started by an "s:link propagation=begin" link on the ViewBid page, and ended either with a save() action or the cancel() action.
This is the series of actions that cause the exception: ViewBid--link to -->ReqCorr--action cancel()-->ViewBid--link to -->ReqCorr (boom!)
I have tried to provide this a simple ascii flowchart :) :
Page View ConversationType CID ========= ================ === Home New tmp 2 | V ViewBid tmp 2 | begin (via s:link) | V ReqCorr tmp prom. to long 4 | end (cancel()) | V ViewBid long dem. to tmp 4 | begin (via s:link) | V ReqCorr IllegalStateEx. long-running conversation already active
The cid is taken from Live HTTP Headers in FireFox. This is the comlplete interaction captured by Live HTTP Headers:
http://localhost:8080/MyApp/home.jsf?cid=2 GET /MyApp/home.jsf?cid=2 HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/home.jsf Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Sat, 07 Apr 2007 07:20:00 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/restricted/bidderViewBid.jsf GET /MyApp/restricted/bidderViewBid.jsf HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/home.jsf?cid=2 Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Sat, 07 Apr 2007 07:20:05 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin GET /MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/restricted/bidderViewBid.jsf Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Sat, 07 Apr 2007 07:20:07 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/block/receive-send-updates POST /MyApp/block/receive-send-updates HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin Content-Length: 733 Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 Pragma: no-cache Cache-Control: no-cache partial=false&ice.event.target=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id52&ice.event.captured=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id52&ice.event.type=onclick&ice.event.alt=false&ice.event.ctrl=false&ice.event.shift=false&ice.event.meta=false&ice.event.x=159&ice.event.y=363&ice.event.left=true&ice.event.right=false&=&bidderReqCorrForm=bidderReqCorrForm&icefacesCssUpdates=&viewNumber=1&icefacesID=moKDNfCx_bC5P8I-kPXRgA&cid=4&bidderReqCorrForm%3AreqBidCorrReason=dddd&focus_hidden_field=&bidderReqCorrForm%3A_ideventModel=&bidderReqCorrForm%3A_idcl=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id52&focus=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id52&icefacesID=moKDNfCx_bC5P8I-kPXRgA%2C&viewNumber=1%2C&rand=0.5697510197840187 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=UTF-8 Content-Length: 2396 Date: Sat, 07 Apr 2007 07:20:10 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/block/receive-send-updates POST /MyApp/block/receive-send-updates HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin Content-Length: 824 Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 Pragma: no-cache Cache-Control: no-cache partial=false&ice.event.target=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id53&ice.event.captured=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id53&ice.event.type=onclick&ice.event.alt=false&ice.event.ctrl=false&ice.event.shift=false&ice.event.meta=false&ice.event.x=330&ice.event.y=370&ice.event.left=true&ice.event.right=false&=&bidderReqCorrForm=&icefacesCssUpdates=&viewNumber=1&icefacesID=moKDNfCx_bC5P8I-kPXRgA&cid=&bidderReqCorrForm%3AreqBidCorrReason=dddd&bidderReqCorrForm%3AbidItemsTable%3A0%3A_id43=1000&bidderReqCorrForm%3AbidItemsTable%3A0%3A_id50=1000000000&focus_hidden_field=&bidderReqCorrForm%3A_ideventModel=&bidderReqCorrForm%3A_idcl=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id53&focus=bidderReqCorrForm%3AbidItemsTable%3A0%3A_id53&icefacesID=moKDNfCx_bC5P8I-kPXRgA%2C&viewNumber=1%2C&rand=0.31415903347128993 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=UTF-8 Content-Length: 3058 Date: Sat, 07 Apr 2007 07:20:17 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/block/receive-send-updates POST /MyApp/block/receive-send-updates HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin Content-Length: 659 Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 Pragma: no-cache Cache-Control: no-cache partial=false&ice.event.target=bidderReqCorrForm%3AcancelBtn&ice.event.captured=bidderReqCorrForm%3AcancelBtn&ice.event.type=onclick&ice.event.alt=false&ice.event.ctrl=false&ice.event.shift=false&ice.event.meta=false&ice.event.x=114&ice.event.y=419&ice.event.left=true&ice.event.right=false&bidderReqCorrForm%3AcancelBtn=Cancel&bidderReqCorrForm=&icefacesCssUpdates=&viewNumber=1&icefacesID=moKDNfCx_bC5P8I-kPXRgA&cid=&bidderReqCorrForm%3AreqBidCorrReason=dddd&focus_hidden_field=&bidderReqCorrForm%3A_ideventModel=&bidderReqCorrForm%3A_idcl=&focus=bidderReqCorrForm%3AcancelBtn&icefacesID=moKDNfCx_bC5P8I-kPXRgA%2C&viewNumber=1%2C&rand=0.006728861660381558 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 X-REDIRECT: /MyApp/restricted/bidderViewBid.jsf?bidId=950272&cid=4 Content-Length: 1 Date: Sat, 07 Apr 2007 07:20:19 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/restricted/bidderViewBid.jsf?bidId=950272&cid=4 GET /MyApp/restricted/bidderViewBid.jsf?bidId=950272&cid=4 HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin Cookie: redirectViewNumber=1,; redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/html;charset=UTF-8 Transfer-Encoding: chunked Date: Sat, 07 Apr 2007 07:20:19 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin GET /MyApp/restricted/reqBidCorrection.jsf?bidId=950272&conversationPropagation=begin HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/restricted/bidderViewBid.jsf?bidId=950272&cid=4 Cookie: redirectViewNumber=1,; redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 302 Moved Temporarily Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Location: http://localhost:8080/MyApp/debug.jsf?cid=4&clr=true Content-Length: 0 Date: Sat, 07 Apr 2007 07:20:24 GMT ---------------------------------------------------------- http://localhost:8080/MyApp/debug.jsf?cid=4&clr=true GET /MyApp/debug.jsf?cid=4&clr=true HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Accept-Language: en-us,en;q=0.8,sv;q=0.5,ar;q=0.3 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://localhost:8080/MyApp/restricted/bidderViewBid.jsf?bidId=950272&cid=4 Cookie: redirectViewNumber=1,; JSESSIONID=349D78AD4B524645E6CD3F62500FBD21 HTTP/1.x 200 OK Server: Apache-Coyote/1.1 Cache-Control: must-revalidate Pragma: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Type: text/html;charset=ISO-8859-1 Transfer-Encoding: chunked Date: Sat, 07 Apr 2007 07:20:24 GMT ----------------------------------------------------------
pages.xml:
<page view-id="/restricted/bidderViewBid.xhtml"> <restrict>#{s:hasRole('Bidder')}</restrict> <param name="bidId" value="#{bidHome.id}" converterId="javax.faces.Long"/> <navigation from-action="#{bidderViewBidManager.createBid}"> <redirect view-id="/restricted/createBid.xhtml"/> </navigation> ... </page> <page view-id="/restricted/reqBidCorrection.xhtml"> <restrict>#{s:hasPermission('bbrules', 'bidderRules', 'canReqCorrection')}</restrict> <param name="bidId" value="#{bidHome.id}" converterId="javax.faces.Long"/> <navigation from-action="#{bidderBidCorrectionManager.save}"> <redirect view-id="/restricted/bidderViewBid.xhtml"/> </navigation> <navigation from-action="#{bidderBidCorrectionManager.cancel}"> <redirect view-id="/restricted/bidderViewBid.xhtml"/> </navigation> </page>
Link in ViewBid:
<s:link value="#{messages.label_ReqBidCorrection}" view="/restricted/reqBidCorrection.xhtml" propagation="begin"> <f:param name="bidId" value="#{bidHome.id}"/> </s:link>
And code in bidderBidCorrectionManager:
@End public void cancel(){ initCorrections(); reason = null; dirty = false; }
Now, I ran this scenario with debug level logging and I see that in the restore view phase when it is trying to display the second ReqCorr view (after the cancel), a cid parameter is passed along:
[2007-04-07 10:44:19,296] DEBUG org.jboss.seam.core.Manager Found conversation id in request parameter: 4
[2007-04-07 10:44:19,296] DEBUG org.jboss.seam.core.Manager Restoring conversation with id: 4
However, reading through the Live HTTP Header log, I cannot see when or where this is happening, and why should it? This conversation was ended two requests ago! Also, when a temp. conv. is promoted to long running, does it get a new id? That would explain the change in cid the first time I go into ReqCorr (cid 2 to 4).
Two workarounds I found. One is to @End(beforeRedirect=true) on the cancel method. Problem with that is that when I go back again, I get that message "Conversation ended...". If I want to, I can convince myself that this message makes sense, but to a user? The other option is to change propagation=begin to propagation=join on the s:link. This works, with no side effects. But I do not understand WHY I have to do that?
There must be something I'm missing here :)
P.S. Sorry about the formatting, cant figure that one out either, LOL