1 Reply Latest reply on Jun 4, 2011 3:40 PM by kongo09

    Conversation, pretty URL, base URL and POST

    kongo09 Newbie

      I'm pretty new to Seam and its concept of conversations, so I would love to reach out to the experts to get some feedback on my thoughts.

      The goal is to run part of an application covering several views in a conversation. The conversation is supposed to use pretty URLs that are RESTful using a business key. There will be two main entrances into the conversation: a) the user can navigate to a starting page via some interface links and b) the user can enter the starting page address directly and go there with a GET

      For a) I intend to retrieve (or create) the appropriate business key and then use that as a page parameter to redirect to the view-id of the starting page

      For b) I need to catch the page parameter directly from the URL

      In the pages.xml I've given my conversation a name:

       <conversation parameter-name="productCoreKey" name="Core" parameter-value="#{productCoreKey}"/>

      And I use that with the starting page of the conversation as follows:

       <page view-id="/view.xhtml" conversation="Core">
        <action execute="#{library.showProductCore}" on-postback="false"/>
        <rewrite pattern="/view/{productCoreKey}"/>
        <rewrite pattern="/view"/>
         <rule if-outcome="failed">
          <redirect view-id="/error.xhtml"/>

      The first stumbling block is that when I use the @Begin annotation in library.showProductCore I get an exception telling me that I cannot start a new conversation if a long-running conversation is already active. I don't understand that, as I haven't started any other conversation in the code. Or is naming the conversation in the <page> element already starting the conversation? If I use @Begin(join=true) I don't get an error.

      The next stumbling block is managing the paths of the view.xhtml file. It uses quite a few relative URLs from the site template to include stylesheets and stuff. However, with the URLs now being rewritten from http://host/context-root/view to http://host/context-root/view/productCoreKey all the relative URLs don't work anymore. Is there a way to make them absolute by getting the context root as an EL and putting that into the path?

      The third stumbling block is the treatment of JSF POST requests that seem to remove the conversation id from the URL. This prevents the result page from being bookmarkable (and also breaks relative URLs). What's the way to deal with this?

      Thanks so much. I've looked at the online docu but found it rather short and I also read the Seam in Action book, but still struggle.

        • 1. Re: Conversation, pretty URL, base URL and POST
          kongo09 Newbie

          Ok, I think I solved my second problem. I've put the following line into the components.xml

          <factory name="contextPath" value="#{facesContext.externalContext.request.contextPath}"/>

          Now I can use #{contextPath} at the start of all my css inclusions in the xhtml files making the relative URLs absolute and consequently making them work independently of any URL rewriting as part of the conversation setup. Not sure if this is the way one is supposed to do this, but it works.