Sam Martin
Sam Martin

Reputation: 1031

Navigation on validation failure in Seam/JSF

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).

Upvotes: 1

Views: 1609

Answers (1)

Peter Hilton
Peter Hilton

Reputation: 17344

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.

Upvotes: 1

Related Questions