Search code examples
jsfcdijsf-2.2omnifaces

@ConversationScoped bean behaves as @RequestScoped since OmniFaces 2.5 FacesViews


I tried to upgrade my Java EE 7 / JSF 2.2 application to Omnifaces 2.6. Currently I am running version 2.4. After that, I have noticed a strange behavior when using @ConversationScoped and Ajax-Requests. When calling, the area, which should get rendered after the request, gets cleared (no exception on the server, response status code 200).

Next, I have a kind of wizard implementation, based on @ConversationScoped. It holds a class called ViewManager which has itself a List of Views. Initializing works fine and this list gets filled. But somehow it gets cleared (set to null) when the first form/view gets submitted. The setter for this is never called after the initialization, so it is not changed by my code. Somehow the view manager instance is still available, only this list of view within the view manager is null, which is kind of strange.

With omnifaces 2.4, everything did work fine (this is why I did not add some code of my wizard). I checked the changelog and noticed the MultiViews configuration when using ExtensionlessURLs. Don't know why this could effect my problem, but i tried it...with no success. I have no idea what could be the problem, so maybe you can help me.

Thanks in advance :)


Solution

  • In OmniFaces, the FacesViews extensionless URLs feature got in version 2.5 an overhaul in order to support the so-called MultiViews as you can read on this blog.

    During this overhaul I made a backwards compatibility mistake in the FacesViewsViewHandler where the <h:form> action URL is being manipulated in order to include the virtual folders of the MultiViews feature. The query string parameters were dropped from the original action URL and not added back.

    The @ConversationScoped relies on the cid request parameter being present in the <h:form> action URL as in /context/page?cid=1. This thus became /context/page and therefore the conversation isn't retained across postbacks.

    I will fix this in next OmniFaces release, for now you can get back the desired behavior by adding the below context parameter to web.xml.

    <context-param>
        <!-- Workaround for disappearing @ConversationScoped ?cid= parameter -->
        <!-- This can be removed in next OmniFaces version after 2.6 -->
        <param-name>org.omnifaces.FACES_VIEWS_VIEW_HANDLER_MODE</param-name>
        <param-value>BUILD_WITH_PARENT_QUERY_PARAMETERS</param-value>
    </context-param>
    

    This parameter triggers a different way of building the URL whereby the entire query string from the original action URL is explicitly retained.