tags:

views:

1879

answers:

2

I'm doing a project in seam that requires restful URLs. I have a view that is mapped to /group/{group}/{locale}. On that page I have a list of so called messages. Each message has a button to save changes to the message. This is linked to an action bean like this:

<h:commandButton type="submit" value="Save Changes" action="#{groupAction.update}" />

Each message has an anchor, so /group/{group}/{locale}#{id} can be used to make the browser go to that anchor. This is why I need a redirect after the POST:

<page view-id="/group.xhtml">
  <rewrite pattern="/group/{group}/{locale}"/>

  <param name="group" value="#{groupAction.group}"/>
  <param name="locale" value="#{groupAction.locale}"/>

  <navigation from-action="#{groupAction.update}">
    <redirect view-id="/group.xhtml?group=#{group}&locale=#{locale}##{id}"/>
  </navigation>
</page>

Also I have the following redirect rule (UrlRewriteFilter) to get to the proper RESTful URL:

<outbound-rule>
  <from>^/group.xhtml\?group=([\.\w]+)&locale=([\.\w]+)\#([\.\w]+)\?cid=(\d*)$</from>
  <to type="temporary-redirect" last="true">/group/$1/$2#$3</to>
</outbound-rule>

I strip the conversationId here. This has been tested an works. However seam still appends a '?conversationId={cid}'. So what's the problem? Well, imagine a URL like '/group/{group}/{locale}#{id}?conversationId={cid}'. Oviously the browser doesn't like this and will not automatically go to that anchor.

I did some research and discovered my problem in the seam documentation:

29.1.4.2. Conversation propagation with redirects This filter allows Seam to propagate the conversation context across browser redirects. It intercepts any browser redirects and adds a request parameter that specifies the Seam conversation identifier. The redirect filter will process all requests by default, but this behavior can also be adjusted in components.xml:

<web:redirect-filter url-pattern="*.seam"/>

I don't need the redirect-filter and I tried putting something invalid in the url-pattern to "disable" the filter. However that didn't work. So my question is now:

How do I disable the redirect-filter in seam?

I can't find the answer. The seam documentation talks about disabling it in web.xml, but my attempts have not been succesful yet.

+1  A: 

OK, I managed to kill the redirect-filter by adding this to my compononents.xml:

<web:redirect-filter disabled="true" installed="false" />

However my main problem still exists, so that was apparently not the problem. It still adds the conversationId as an extra query string on the URL. Apperently I'm doing something wrong since it has been done before.

@Adeel Ansari:

components.xml:

 <web:rewrite-filter view-mapping="/seam/*" />

pages.xml see my initial question.

Matthias van der Vlies
Have you configured UrlRewriteFilter, in your web.xml?
Adeel Ansari
Yes I have and UrlRewriteFilter is working, but still seam adds the ?conversationId
Matthias van der Vlies
Have you tried removing SeamRedirectFilter from your web.xml completely? may be just to test the case.
Adeel Ansari
SeamRedirectFilter is not in my web.xml and never has been. org.jboss.seam.servlet.SeamFilter is the only filter I have apart from the UrlRewriteFilter and the the Faces filter
Matthias van der Vlies
Does rewrite-filter mapping in components.xml, match UrlRewriteFilter mapping in web.xml?
Adeel Ansari
+4  A: 

I've worked out where the unwanted conversationId query string parameter is coming from.

The <redirect/> results in a call to org.jboss.seam.faces.FacesManager.redirect(String viewId, Map<String, Object> parameters, boolean includeConversationId)

This is called from the following code in org.jboss.seam.faces.Navigator which sets includeConversationId to true:

  FacesManager.instance().redirect(viewId, parameters, true);

I cannot see any way to avoid this, so the fix/workaround is to do the redirect programmatically in the action method with:

  FacesManager.instance().redirect(viewId, parameters, false);
Peter Hilton