【问题标题】:Code jumps to unknown class while executing method in backing bean在支持 bean 中执行方法时代码跳转到未知类
【发布时间】:2013-04-15 02:41:02
【问题描述】:

我有一个问题,我在支持 bean 中调用了一个方法,该方法应该更新一个列表,之后在我的 xhtml 页面上重新呈现rich:datagrid 以反映更改。通过调试我可以确认该方法被调用但是它成功地在列表中的一次迭代后跳出方法并转到另一个类(不是我的类之一)。它永远不会返回到方法并且数据网格也永远不会重新呈现。

下面是相关的html和java代码。 HTML:

<table width="650px">
    <tbody>
        <tr>
            <td width="325px" align="left"><h:outputText style="white-space: pre; font-weight: normal; font-family: Tahoma; font-size: 11px">Name :</h:outputText>
                <h:inputText id="searchName" size="25" value="#{myBean.searchName}"></h:inputText></td>
            <td width="325px" align="left"><h:outputText style="white-space: pre; font-weight: normal; font-family: Tahoma; font-size: 11px">Surname :</h:outputText>
                <h:inputText id="searchSurname" size="25" value="#{myBean.searchSurname}"></h:inputText></td>
        </tr>
        <tr>
            <td width="325px" align="left"><h:outputText style="white-space: pre; font-weight: normal; font-family: Tahoma; font-size: 11px">ID :</h:outputText>
                <h:inputText id="searchId" size="25" value="#{myBean.searchId}"></h:inputText></td>
            <td width="325px" align="left"><h:outputText style="white-space: pre; font-weight: normal; font-family: Tahoma; font-size: 11px">Status :</h:outputText>
                <h:inputText id="searchStatus" size="25" value="#{myBean.searchStatus}"></h:inputText></td>
        </tr>
        <tr>
            <td align="right"><a4j:commandButton action="#{myBean.searchRecords}" value="Search" render="dataList"></a4j:commandButton></td>
        </tr>
    </tbody>
</table>

Java:

public void searchRecords(){
    if(dataList == null){
        dataList = searchList;
    }

    searchList = Collections.<ListObj>emptyList();

    for (ListObj obj : dataList) {
        if((obj.getName().contains(searchName)) | (obj.getSurname().contains(searchSurname)) | (obj.getIdNumber().contains(searchId)) | (obj.getStatus().equalsIgnoreCase(searchStatus))){
            searchList.add(obj);
        }
    }
}

代码跳转到 searchList.add(obj) 上的未知类。我使用的是 Apache MyFaces JSF 2.1、RichFace 4.3 和 Java 1.6。我认为这可能与 JSF 生命周期有关,因为我对生命周期的理解严重缺乏,但出于同样的原因,我可能错了。不过,我正在阅读 BalusC 关于生命周期的帖子。

【问题讨论】:

  • 你能告诉我们你的调试器显示正在执行的未知类和方法的名称是什么吗?

标签: java jsf-2 richfaces myfaces


【解决方案1】:

您的根源是您试图将元素添加到空列表中。方法Collections.emptyList(); 返回定义在类Collections 中的特殊内部类EmptyList 的实例。此特殊列表无法修改。尝试向其中添加元素不会修改其内容。

因此,将行 searchList = Collections.&lt;ListObj&gt;emptyList(); 更改为 searchList = Collections.new ArrayList&lt;ListObj&gt;(); 并重试。

【讨论】:

  • 感谢这个答案。我不知道它不只是返回一个空的 ListObj 列表。
猜你喜欢
  • 2013-04-08
  • 2017-10-22
  • 1970-01-01
  • 2015-03-08
  • 2011-06-29
  • 2013-12-02
  • 1970-01-01
  • 2011-02-09
  • 1970-01-01
相关资源
最近更新 更多