【问题标题】:RichFaces 4 and @ViewScopedRichFaces 4 和@ViewScoped
【发布时间】:2011-07-29 16:55:09
【问题描述】:

我正在从 RichFaces 3.3.3 迁移到 4.0,遇到了一个不知道如何解决的问题。

到目前为止,我已经使用 RichFaces 的@KeepAlive 注解来实现带有 bean 的 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>

豆子:

@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;
    }
}

任何帮助将不胜感激

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

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

    1. 您有一个已提交的字段并且验证/转换失败。如果您有验证或转换错误,您的操作将不会被调用。你应该有一个&lt;h:messages&gt; 以确保你看到它,因为它是a4j:clickLink 把它放在a4j:outputPanel 中,就像这样:&lt;a4j:outputPanel ajaxRendered="true"&gt;&lt;h:messages/&gt;&lt;/a4j:outputPanel&gt;

    2. 您在另一个&lt;h:form&gt; 中有&lt;h:form&gt;,并且您正在尝试提交内部的。你可以用 firebug 来跟踪这个,真的很容易。 JSF 出于某种原因决定什么都不做。

    看起来你在这里做一些时髦的事情:

    1. 重新呈现表单。我在 JSF2 中重新渲染 &lt;h:form&gt;s 时遇到了严重的问题(即它们停止工作),尤其是。使用richfaces 模态面板,通过他们实现实际面板的方式使其成为可能,他们将内容从&lt;body&gt; 元素中的DOM 中的任何位置移动。因此,我建议在表单中创建一个&lt;h:panelGrid&gt;,然后重新渲染那个。
    2. &lt;f:setPropertyActionListener&gt;。真的吗?你也应该有 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}"/>
    

    【讨论】:

    • 感谢您的建议,但方法 myBean.未调用 selectCustomer(customer)。
    • 只是关于范围的评论,RichFaces 4 将没有视图范围 (a4j:keepAlive),因为它现在可从 JSF 2 获得。
    • 可能无法调用您的操作的原因有两个: 1. 您有一个已提交的字段并且验证/转换失败。如果您有验证或转换器错误,您的操作将不会被调用。你应该有一个&lt;h:messages&gt; 以确保你看到它,或者在web.xml 中将开发阶段设置为开发(我到办公室时会给你实际的sn-p)。 2.您在另一个&lt;h:form&gt; 中有一个&lt;h:form&gt;,并且您正在尝试提交内部的。你可以用 firebug 来跟踪这个,真的很容易。 PS:我讨厌stackoverflow格式。
    猜你喜欢
    • 2012-04-04
    • 2012-02-11
    • 2021-06-23
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2013-12-19
    • 2012-08-15
    相关资源
    最近更新 更多