gpt4 book ai didi

jsf - RichFaces 4 和 @ViewScoped

转载 作者:行者123 更新时间:2023-12-02 07:41:19 25 4
gpt4 key购买 nike

我正在从 RichFaces 3.3.3 迁移到 4.0,并且遇到了一个无法解决的问题。

到目前为止,我已经使用 RichFaces 的@KeepAlive 注释来通过 beans 实现 View 范围,但新版本 4 到目前为止还没有这样的功能(据我所知)。所以我认为 @ViewScoped 注释将是自然(且快速)的替代品,但它不起作用。这是给我带来麻烦的相关代码。它呈现一个包含客户名称的表格作为链接,因此当单击名称时,它会弹出一个弹出窗口来编辑数据。它在 v3.3.3 中与 @KeepAlive 一起工作,但在 v4 与 @ViewScoped 中不起作用(弹出窗口不会被调用)。

页面:

<h:form prependId="false">
<rich:dataTable id="table" value="#{myBean.customers}" var="customer">
<!--...headers...-->
<h:column>
<a4j:commandLink action="#{myBean.selectCustomer}"
oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor">
${customer.name}
<f:setPropertyActionListener value="#{customer}" target="#{myBean.selectedCustomer}"/>
</a4j:commandLink>
</h:column>
<h:column>${customer.address}</h:column>
</rich:dataTable>
</h:form>

<rich:popupPanel id="popup_customer_editor>
<h:form id="form_customer_editor">
<!--...form fields...-->
</h:form>
</rich:popupPanel>

bean :

@ManagedBean
@ViewScoped //It was @KeepAlive before
public class MyBean implements Serializable
{
private String name;
private String address;
private Customer selectedCustomer; //POJO class
//getters and setters
...
public String selectCustomer()
{
name = selectedCustomer.getName();
address = selectedCustomer.getAddress();

return null;
}
}

如有任何帮助,我们将不胜感激

最佳答案

您的操作可能不会被调用有两个原因:

  1. 您已提交一个字段,但验证/转换失败。如果您出现验证或转换错误,您的操作将不会被调用。你应该有一个<h:messages>确保您看到它,并且由于它是 a4j:clickLink 将其放入 a4j:outputPanel 中像这样:<a4j:outputPanel ajaxRendered="true"><h:messages/></a4j:outputPanel> .

  2. 您有<h:form>在另一个里面<h:form> ,并且您正在尝试提交内部的。您可以使用 firebug 来跟踪它,非常非常简单。由于某种原因,JSF 决定不做任何事情。

看来您在这里做着一些奇怪的事情:

  1. 重新呈现表单。我在重新渲染时遇到严重问题 <h:form> JSF2 中的 s(即它们停止工作),尤其是。使用 richfaces 模式面板,通过他们实现实际面板的方式实现,他们将内容从 <body> 中 DOM 中的任何位置移动。元素。因此我建议创建一个 <h:panelGrid>在表单内,然后重新渲染该表单。
  2. <f:setPropertyActionListener> 。真的吗?您还应该有 EL2,因此您可以更改此设置:

    <a4j:commandLink action="#{myBean.selectCustomer}"
    oncomplete="#{rich:component('popup_customer_editor')}.show();"
    render="form_customer_editor">
    ${customer.name}
    <f:setPropertyActionListener value="#{customer}"
    target="#{myBean.selectedCustomer}"/>
    </a4j:commandLink>

<a4j:commandLink action="#{myBean.selectCustomer(customer)}"
oncomplete="#{rich:component('popup_customer_editor')}.show();" render="form_customer_editor" value=#{customer.name}"/>

关于jsf - RichFaces 4 和 @ViewScoped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5547863/

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