0
votes

I have a problem where I call a method in the backing bean which is supposed to update a list after which a rich:datagrid is rerender on my xhtml page to reflect the changes.Via debugging I can confirm that the method is called succesfully however it jumps out of the method after one iteration throught the list and goes to a different class(not one of my classes).It never returns to the method and the datagrid is also never rerendered.

Below is the relevant html and java code. 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);
        }
    }
}

The code jumps to the unkown class on searchList.add(obj).I am using Apache MyFaces JSF 2.1, RichFace 4.3 and Java 1.6. I think this might have something to do with the JSF lifecycle as my understanding of the lifecycle is severly lacking,but I could be wrong about that for the same reason.I am in the process of reading a post by BalusC about the lifecycle though.

1
Can you tell us what is the name of unknown class and method that your debugger shows to be executing ?Apurv

1 Answers

0
votes

Your source cause is that you are trying to add elements to empty list. Method Collections.emptyList(); returns instance of special inner class EmptyList defined into class Collections. This special list cannot be modified. Attempt to add elements to it will not modify its content.

So, change line searchList = Collections.<ListObj>emptyList(); to searchList = Collections.new ArrayList<ListObj>(); and try again.