1

We all know that it is possible to write Single Page Applications with JSF 2, by using some clever AJAX updates on a component such as < h:panelGroup >.

Example here: Single Page Applications with JSF

However, I'm wondering if it is possible to use the SPA approach with the Conversation Scope in JSF 2.

As I know, the Conversation Scope relies on the "cid" parameter appended to the URL query string, to locate the correct conversation within a session, which implicitly means it only supports "conventional" multi-page navigation, with full GET or POST requests to load new fresh xhtml pages.

Is there any way to support the SPA approach and the Conversation Scope ? In other words, when updating a panel on the screen with a new facelet fragment, references to a Conversation Scoped bean should still refer to the same instance, instead of creating a new one ( because of the lack of a "cid" parameter in the URL )

Thanks a lot in advance !

Maikel Nait
  • 251
  • 3
  • 18
  • So you haven't actually tested it? Why not? If you did you'd for long know that it by default just works. – BalusC Mar 24 '16 at 08:56
  • Thanks for the reply. I actually "tried" to test it, but failed to succeed, due to my lack of knowledge on this particular subject. Therefore what I'm probably looking for is some kind of "working snippet sample code" ... – Maikel Nait Mar 24 '16 at 09:17
  • You're basically asking for a "working snippet sample code using standard JSF without Bootsfaces"? In that case, is this helpful? http://stackoverflow.com/q/7108668 – BalusC Mar 24 '16 at 10:06
  • What I'm looking for, is a way to use the SPA approach ( no matter if using BootFaces, PrimeFaces or plain JSF ) together with Conversation Scoped beans. So far, in my current project, every time an AJAX request is triggered for loading a new SPA facelet, a new instance of the same Conversation Scoped bean referenced in these facelets is created. I believe it is due to the fact that the AJAX request does not contain the "cid" parameter ... – Maikel Nait Mar 24 '16 at 10:40
  • In my case, when using the kickoff snippet in abovelinked Q&A, the conversation was maintained (i.e. bean is not recreated). The cid parameter is properly present in the request without any additional effort (via the generated
    ). I suggest to carefully read http://stackoverflow.com/tags/jsf/info and trash/reframe your question accordingly. Right now no one can reproduce your problem based on the information provided so far. Concrete MVCE code examples really help us in order to reproduce/see/debug your problem instead of a bunch of half facts, guesses and assumptions.
    – BalusC Mar 24 '16 at 10:57
  • Yep, I will try to post a minimal code snippet to illustrate the problem I'm facing... – Maikel Nait Mar 24 '16 at 11:12
  • Problem solved!! It turns out that there was a mistake when trying to start a Conversation. We were checking **!**conversation.isTransient() ( false ) instead of true, for determining if conversation.begin() should be executed. After fixing that clumsy mistake, Conversation Scoped beans just started to behave as expected even with SPA navigation. AMAZING – Maikel Nait Mar 25 '16 at 08:13

1 Answers1

0

Problem solved!! It turns out that there was a mistake when trying to start a Conversation. We were checking if (! conversation.isTransient()) ( false ) instead of true, for determining if conversation.begin() should be executed. After fixing that clumsy mistake, Conversation Scoped beans just started to behave as expected, even with SPA navigation. AMAZING !

Maikel Nait
  • 251
  • 3
  • 18