Omnifaces Faces.redirect失去了对话范围 [英] Omnifaces Faces.redirect loses conversation scope

查看:142
本文介绍了Omnifaces Faces.redirect失去了对话范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对org.omnifaces.util.Faces#redirect和对话作用域bean有问题:

I have problem with org.omnifaces.util.Faces#redirect and conversation scoped bean:

有一个按钮

<p:commandButton action="#{navigationHandler.gotoCreateCar}"
  actionListener="#{createHandler.init(searchHandler.search())}
  value="#{msg.search}" update=":articleSearchForm">
  <f:param name="cid" value="#{javax.enterprise.context.conversation.id}"/>
</p:commandButton>

在对话范围的bean:createHandler初始化之后,必须在相同的对话范围内导航到createCar页面.

which must do a navigation to createCar page within the same conversation scope after init of my conversation scoped bean: createHandler.

在NavigationHandler#gotoCreateCar中,仅是Faces.redirect(createCarPage)的调用.

In the NavigationHandler#gotoCreateCar is just a call of Faces.redirect(createCarPage).

如果我喜欢这样做,则不会传输参数cid,并且我失去了对话.

If I do like this the parameter cid is not transfered and I lose my conversation.

如果我在faces-config.xml中定义导航规则:

If I define a navigation rule in faces-config.xml:

<navigation-case>
  <from-outcome>createCar</from-outcome>
  <to-view-id>/portal/createCar.xhtml</to-view-id>
  <redirect />
</navigation-case>

,然后在NavigationHandler#gotoCreateCar中返回所需的结果-即可正常工作.

and in the NavigationHandler#gotoCreateCar just return the needed outcome - then it works fine.

也许我不了解这两种导航方法之间差异的每个细节.如果有人可以帮助我理解问题,我将不胜感激.

Maybe I do not understand every detail in the difference between this two navigation approaches. I would be appreciated if somebody could help me to understand the problem.

谢谢!

推荐答案

对话传播由导航处理程序处理. Faces#redirect() 委托给 Faces#navigate() 代替,它委托给

The conversation propagation is handled by the navigation handler. The Faces#redirect() delegates to ExternalContext#redirect() which does not use the navigation handler. You'd better use Faces#navigate() instead which delegates to NavigationHandler#handleNavigation().

public void gotoCreateCar() {
    // ...

    Faces.navigate("/portal/createCar.xhtml?faces-redirect=true");
}

(注意:在这种情况下,无需<navigation-case>)

或者,只需从action方法返回该字符串即可.

Alternatively, just return exactly that string from the action method.

public String gotoCreateCar() {
    // ...

    return "/portal/createCar.xhtml?faces-redirect=true";
}    

Faces#navigate()仅在您处于不支持返回导航案例结果(例如@PostConstructpreRenderView)的(侦听器)方法内时有用.

The Faces#navigate() is only useful when you're inside a (listener) method which doesn't support returning a navigation case outcome, such as @PostConstruct or preRenderView.

这篇关于Omnifaces Faces.redirect失去了对话范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆