简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM