tags:

views:

867

answers:

1

I've been playing with Seam (2.0.2.SP1) for a few weeks, and I have most of the basics nailed down, but I haven't come up with a decent solution to the following.

Suppose I have a form at /foo.xhtml, with a rewrite rule such that URLs like /foo.seam?id=<fooId> are converted to /foo/<fooId>. There's a commandButton on the form with an action of #{fooHome.update}. I also have a navigation rule in /foo.page.xml that redirects back to a nice, bookmark-friendly GET after a successful POST:

<navigation from-action="#{fooHome.update}">
    <rule if-outcome="updated">
        <redirect view-id="/foo.xhtml">
            <param name="id" value="#{fooHome.instance.id}"/>
        </redirect>
    </rule>
</navigation>

The problem is when a validation error occurs, at which point the navigation rules get skipped, and I end up at /foo after the POST.

My question: Is there a way to redirect on validation errors, so I end up with a GET request for /foo/<fooId> instead of the POST to /foo?

I tried rolling my own validation methods in fooHome, returning a "failed" outcome, but I don't really want invalid data getting past the validation phase (and thus into the current conversation).

+1  A: 

You would normally redisplay the same view on a validation failure, rather than redirect. Assuming that you are using UrlRewrite for the rewrite rules, perhaps you can use an outbound-rule so that the /foo/{fooId} URL is still shown in this case.

Peter Hilton
I am indeed using UrlRewrite, but I can't seem to construct such an outbound-rule. <h:form/> uses the current view (/foo) as the action, not the rewritten URL (/foo/<fooId>). Unless I'm missing something (entirely possible), I don't see a way to get <fooId> into an outbound-rule.
CapnNefarious
In the end, I just reworked my form to stay on the same view on validation failure, as you suggest. I'm still curious if there's a way to do what I was originally hoping, but this will work for now.
CapnNefarious