【问题标题】:How to create a link or button which calls an action and doesn't preserve cid?如何创建调用操作且不保留 cid 的链接或按钮?
【发布时间】:2012-02-07 02:26:47
【问题描述】:

这是一个我无法实现的简单用例:我想创建一个链接或按钮,它调用服务器方法(操作)并将重定向到页面而不保留 cid 参数。

我正在使用 JSF2、JBoss 7 和 Seam 3。

这是我试过的两种方法,但都没有成功。

第一个,h:commandLink

<h:commandLink action="pages/home.xhtml"
               actionListener="#{identity.logout()}"
               value="#{bundles.layout.logout}" />

这里调用了identity.logout(),但是浏览器被重定向到pages/home.xhtml?cid=1,所以如果我再次登录,我会得到一个

org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped

错误。

第二个,h:link

<h:link outcome="/pages/home.xhtml" value="#{bundles.layout.logout}">
    <f:ajax event="click" listener="#{identity.logout()}" />
</h:link>

这里,我生成的超链接中没有cid,但是没有调用方法identity.logout()...

有人有想法吗?

【问题讨论】:

    标签: jsf-2 cdi conversation-scope


    【解决方案1】:

    使用h:commandLink 并从identity.logout() 调用conversation.end() 应该可以工作。您没有包含identity.logout() 的代码,但我怀疑您并没有结束对话。通过结束对话,您将其从长时间运行更改为瞬态,此时不应传播。

    【讨论】:

    • identity.logout()的代码是Seam's 3 security module。它不调用conversation.end(),而是调用session.invalidate()。此外,我创建了一个调用conversation.end() 的PostLoggedOutEvent 观察者,但没有比这更好的了:它仍然重定向到pages/home.xhtml?cid=X,其中X 是注销前的当前对话ID。
    猜你喜欢
    • 2011-06-22
    • 2017-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 2011-08-15
    相关资源
    最近更新 更多