如何创建调用操作且不保留 cid 的链接或按钮?

发布于 2024-12-26 10:17:57 字数 1077 浏览 4 评论 0原文

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

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

以下是我尝试过但没有成功的两种方法。

第一个,h:commandLink

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

这里,identity.logout() 被调用,但是随后,浏览器被重定向到页面/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() 未调用...

有人有想法吗?

Here is a simple usecase which I don't manage to realise : I want to create a link or button which calls a server method (action) and will redirect to a page without preserving the cid parameter.

I'm using JSF2, JBoss 7 and Seam 3.

Here are two methods I tried without success.

First one, the h:commandLink

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

Here, identity.logout() is called, but then, the browser is redirected to pages/home.xhtml?cid=1, so if I login again, I will have an

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

error.

Second one, the h:link

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

Here, I don't have any cid in the generated hyperlink, but the method identity.logout() is not called...

Does someone have an idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢欲 2025-01-02 10:17:57

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

Using h:commandLink and calling conversation.end() from identity.logout() should work. You didn't include the code for identity.logout(), but I suspect you're not ending the conversation. By ending the conversation, you change it from long-running to transient, at which point it should not be propagated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文