{"id":1710,"date":"2012-01-27T11:30:42","date_gmt":"2012-01-27T11:30:42","guid":{"rendered":"http:\/\/salientsoft.co.uk\/?p=1710"},"modified":"2012-01-27T11:30:42","modified_gmt":"2012-01-27T11:30:42","slug":"controlling-cdi-conversation-propagation","status":"publish","type":"post","link":"https:\/\/salientsoft.co.uk\/?p=1710","title":{"rendered":"Controlling CDI conversation propagation"},"content":{"rendered":"<p>This is a tricky issue to control correctly. The following points have been found during testing (Mojarra 2.0.4 FCS \/ Primefaces 2.2.1 \/ Glassfish 3.0.1)<\/p>\n<ol>\n<li>One key issue is that to start a new conversation on a page, the navigation to that page must not propagate any previously active conversation. This will then start a new transient (i.e. not long-running\/not started) conversation on the new page, and <em>conversation.begin()<\/em> can be used to make it long-running (i.e. start it).<\/li>\n<li>When doing a standard JSF Ajax postback, the current conversation is always propagated, and it does not appear to be possible to prevent this\/start a new conversation from a postback. JSF always adds the current CID as a querystring parameter<\/li>\n<li>To prevent propagation and to allow a new page to start a new conversation, GET navigation needs to be performed. This fits in well with my main toolbar options \u2013 I use pre-emptive GET navigation for the main pages with full page refreshes.<\/li>\n<li>Primefaces p:button allows the new JSF 2 outcome style GET navigation but cannot be stopped from propagating a conversation \u2013 it always adds a CID parameter. If you add one with an empty or null value, you still get a \u201ccid=\u201d attribute which CDI then spits out as an invalid conversation on the new page.<\/li>\n<li>h:link can be stopped from propagating by using an explicit f:param for the cid, providing the param has no value or an explicit null value (an empty string will not work).<\/li>\n<li>Trying to refer to another inactive conversation, e.g. by storing conversation scoped bean references in a session level map and looking them up, seriously screws up CDI with an extremely long\/possibly recursive stack trace. (See Mantis issue xxx for the stack dump). This is likely to be due to the proxying mechanism used for conversations.<\/li>\n<li>Therefore, it is not possible to invent say a \u2018onPageLeave\u2019 event for a previous page and call it after a new page has started and had its conversation activated.<\/li>\n<li>If therefore I need to refresh all pages for the application, for example if an OptimisticLockException occurred, I use a central workspace session bean to manage all the pages. I set a refresh pending flag in a map for each page, and then when the page is next visited, the workspace bean calls a refresh event of my own for the page, and then clears the pending flag. When processing the current page after an OptimisticLockException, I can refresh directly if the user requests it from a lock dialog.<\/li>\n<li>My workspace bean holds the CID for each page against the page name in a map, and uses this when rendering the Toolbar, adding the appropriate cid= parameter for each toolbar option. In fact I use an outer map keyed on page group name (where the page group corresponds to a top level toolbar option), with an inner map containing all the cids and refresh pending flags for the individual pages in that group. This allows for example a report toolbar option to be a menu of currently active reports, and allows new reports to be created dynamically as new conversations and added to the list under the report menu on the toolbar.<\/li>\n<li>Conversations are started and ended via calls to the workspace bean, which can then add\/remove entries from the maps to keep track of what pages\/cids are currently active.<\/li>\n<li>Regarding navigation and cid propagation, another option is to call JSF directly to obtain the navigation case for an outcome. <em>ConfigurableNavigationHandler<\/em> allows you to pass an outcome and get the actual navigation case, from which you can then get the URL. This should allow full control of the cid= propagation parameter on the querystring, and allow control for components which do not support JSF 2.0 style GET pre-emptive navigation directly from an outcome. The url can be passed to any component which accepts a url, and should then still perform the correct navigation and conversation control. See CoreJSF 3 page 333 for a code example on this. This method could prove useful for example with a Primefaces MenuItem, which does either JSF postback style navigation, or URL navigation, but does not directly do pre-emptive GET navigation by giving it an outcome.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This is a tricky issue to control correctly. The following points have been found during testing (Mojarra 2.0.4 FCS \/ Primefaces 2.2.1 \/ Glassfish 3.0.1) One key issue is that to start a new conversation on a page, the navigation to that page must not propagate any previously active conversation. This will then start a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22],"tags":[110,40,184,112,16,15],"_links":{"self":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1710"}],"collection":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1710"}],"version-history":[{"count":0,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1710\/revisions"}],"wp:attachment":[{"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/salientsoft.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}