gpt4 book ai didi

jsf - RequestScoped bean 在 confirmDialog 中被销毁

转载 作者:行者123 更新时间:2023-12-02 05:44:23 26 4
gpt4 key购买 nike

我有 RequestScoped bean,因为我将用户从带有记录的数据表重定向到编辑页面。在此数据表中,我有删除按钮:

<p:column>
<p:commandButton update=":deleteNewsDialog" oncomplete="deleteNewsDlg.show()" icon="ui-icon-closethick">
<f:setPropertyActionListener value="#{news}" target="#{newsBean.news}" />
</p:commandButton>
</p:column>

这是对话框:

<p:confirmDialog id="deleteNewsDialog" message="Czy na pewno chcesz usunąć wiadomość o tytule &quot;#{newsBean.news.title}&quot;?"
header="Usuwanie wiadomości" severity="alert"
widgetVar="deleteNewsDlg" appendToBody="true">
<h:form>
<p:commandButton value="Usuń" actionListener="#{newsBean.delete}" update=":newsesTableForm:newsesTable, :newsesTableForm:newsGrowl"/>
<p:commandButton value="Anuluj" oncomplete="deleteNewsDlg.hide();"/>
</h:form>
</p:confirmDialog>

当 newsBean.delete 被触发时,newsBean 不再存在,所以我得到了很多丑陋的验证异常。我还有其他像这样的带有 ViewScoped bean 的页面,它在那里工作得很好。帮忙?

最佳答案

请求作用域 bean 的生命周期正好是一个 HTTP 请求/响应。因此,使用表单检索整个 View 已经是一个 HTTP 请求/响应。请求范围的 bean 在响应结束时被丢弃。当您在 View 上发出 ajax 请求时,实际上是在发送一个新的 HTTP 请求。因此,这将创建一个新的请求范围 bean,它在 HTTP 响应结束时被丢弃。因此,同一 View 上的每个 ajax 请求都会获得其自己的请求范围 bean 实例。

如果您需要维护与 View 相关的数据,这不是您想要的。您需要将 bean 放在 View 范围内。只要您通过 ajax 与同一 View 交互并在操作监听器方法中返回 nullvoid,bean 就会存在。请注意,当您返回一个 String 时,即使是空的,也会重新创建 View ,因此 View 作用域的 bean 将被丢弃。

另见:

关于jsf - RequestScoped bean 在 confirmDialog 中被销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10463231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com