在Seam / JSF中验证失败时导航

时间:2022-02-13 16:09:53

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.

我已经和Seam(2.0.2.SP1)玩了几个星期了,我已经把大部分的基础知识搞定了,但是我还没有找到一个像样的解决方案。

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:

假设我在/foo.xhtml上有一个表单,其中包含重写规则,使得像/foo.seam?id= 这样的URL转换为/ foo / 。表单上有一个commandButton,其动作为#{fooHome.update}。我在/foo.page.xml中也有一个导航规则,在成功POST后重定向回一个很好的,书签友好的GET:

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

问题是当发生验证错误时,导航规则被跳过,我在POST后结束于/ foo。

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?

我的问题:有没有办法重定向验证错误,所以我最终得到/ foo / 的GET请求而不是POST到/ 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).

我尝试在fooHome中滚动我自己的验证方法,返回“失败”的结果,但我真的不希望无效数据超过验证阶段(因此进入当前对话)。

1 个解决方案

#1


1  

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.

您通常会在验证失败时重新显示相同的视图,而不是重定向。假设您使用UrlRewrite作为重写规则,也许您可​​以使用出站规则,以便在这种情况下仍然显示/ foo / {fooId} URL。

#1


1  

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.

您通常会在验证失败时重新显示相同的视图,而不是重定向。假设您使用UrlRewrite作为重写规则,也许您可​​以使用出站规则,以便在这种情况下仍然显示/ foo / {fooId} URL。