Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:05:29+00:00 2026-05-28T18:05:29+00:00

I apologize for a lengthy question, but I really need your help. As a

  • 0

I apologize for a lengthy question, but I really need your help. As a part of our project, I’m currently working on a search engine, that updates results list on the fly: the user types in the first 4 characters and up, and as he types, the results list changes. The search value is typed in a text box, while the results are displayed in a Richfaces component rich:extendedDataTable below. If the search value is removed, the result list is empty. I was able to get that working, however, after a few tries I get ConcurrentModificationException, thrown by the component itself. The initial list I am searching comes from the properties file (because I don’t want the search to hit database every time the user types something). I’ve been banging my head over it for months. What am I missing? Let me show you what I’ve done:

This is the input text that should trigger the search logic (I make sure that the table does not get updated when the value is less than 4 characters or if the user presses keys, like arrows, shift, and ctrl – this function is “returnunicode(event)”):

   <h:inputText id="firmname" value="#{ExtendedTableBean.searchValue}">
       <a4j:support reRender="resultsTable" onsubmit="
           if ((this.value.length<4 && this.value.length>0) || !returnunicode(event)) {
               return false;
           }" actionListener="#{ExtendedTableBean.searchForResults}" event="onkeyup" />
   </h:inputText>

Action listener is what should update the list. Here is the extendedDataTable, right below the inputText:

   <rich:extendedDataTable tableState="#{ExtendedTableBean.tableState}" var="item"
                           id="resultsTable" value="#{ExtendedTableBean.dataModel}">

            ... <%-- I'm listing columns here --%>

   </rich:extendedDataTable>

Now, if it’s ok, I would like to show you the back-end code. I only left the logic that’s important to my issue.

 /*
  * To change this template, choose Tools | Templates
  * and open the template in the editor.
  */

 package com.beans;

 import java.io.FileInputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.ConcurrentModificationException;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.CopyOnWriteArrayList;
 import javax.faces.context.FacesContext;
 import javax.faces.event.ActionEvent;
 import org.richfaces.model.DataProvider;
 import org.richfaces.model.ExtendedTableDataModel;

 public class ExtendedTableBean {      
     private String sortMode="single";
     private ExtendedTableDataModel<ResultObject> dataModel;
     //ResultObject is a simple pojo and getResultsPerValue is a method that 
     //read the data from the properties file, assigns it to this pojo, and
     //adds a pojo to the list 

     private Object tableState;
     private List<ResultObject> results = new CopyOnWriteArrayList<ResultObject>();
     private List<ResultObject> selectedResults = 
                                          new CopyOnWriteArrayList<ResultObject>();

     private String searchValue;

     /**
      * This is the action listener that the user triggers, by typing the search value
      */
     public void searchForResults(ActionEvent e) {
        synchronized(results) {
           results.clear();
        }        

        //I don't think it's necessary to clear results list all the time, but here
        //I also make sure that we start searching if the value is at least 4 
        //characters long
        if (this.searchValue.length() > 3) {
           results.clear();
           updateTableList();
        } else {
           results.clear();
        }

        dataModel = null; // to force the dataModel to be updated.
     }

     public List<ResultObject> getResultsPerValue(String searchValue) {
        List<ResultObject> resultsList = new CopyOnWriteArrayList<ResultObject>();

        //Logic for reading data from the properties file, populating ResultObject
        //and adding it to the list

        return resultsList;
     }

     /**
      * This method updates a firm list, based on a search value
      */
     public void updateTableList() {
         try {              
            List<ResultObject> searchedResults = getResultsPerValue(searchValue);

            //Once the results have been retrieved from the properties, empty 
            //current firm list and replace it with what was found.

            synchronized(firms) {
                firms.clear();
                firms.addAll(searchedFirms);
            }
         } catch(Throwable xcpt) {
            //Exception handling
         }
     }

     /**
      * This is a recursive method, that's used to constantly keep updating the 
      * table list.
      */
     public synchronized ExtendedTableDataModel<ResultObject> getDataModel() {
        try {
            if (dataModel == null) {
                dataModel = new ExtendedTableDataModel<ResultObject>(
                            new DataProvider<ResultObject>() {
                               public ResultObject getItemByKey(Object key) {
                                  try {
                                     for(ResultObject c : results) {
                                        if (key.equals(getKey(c))){
                                           return c;
                                        }
                                     }
                                  } catch (Exception ex) {
                                     //Exception handling
                                  }
                                  return null;
                               }

                               public List<ResultObject> getItemsByRange(
                                                     int firstRow, int endRow) {
                                    return Collections.unmodifiableList(results.subList(firstRow, endRow));
                               }

                               public Object getKey(ResultObject item) {
                                     return item.getResultName();
                               }

                               public int getRowCount() {
                                     return results.size();
                               }
                            });
            }
         } catch (Exception ex) {
            //Exception handling    
         }

         return dataModel;
     }

     //Getters and setters 

 }

And like I said, it works fine, but when the user types fast or deletes fast (it’s hard to catch exactly when it happens), ConcurrentModificationException is thrown. Here’s what it looks like exactly:

WARNING: executePhase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@4406b8) threw exception
java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
    at java.util.AbstractList$Itr.next(AbstractList.java:343)
    at org.richfaces.model.ExtendedTableDataModel.walk(ExtendedTableDataModel.java:108)
    at org.ajax4jsf.component.UIDataAdaptorBase.walk(UIDataAdaptorBase.java:1156)
    at org.richfaces.renderkit.AbstractExtendedRowsRenderer.encodeRows(AbstractExtendedRowsRenderer.java:159)
    at org.richfaces.renderkit.AbstractExtendedRowsRenderer.encodeRows(AbstractExtendedRowsRenderer.java:142)
    at org.richfaces.renderkit.AbstractExtendedRowsRenderer.encodeChildren(AbstractExtendedRowsRenderer.java:191)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
    at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
    at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
    at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
    at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
    ...

Synchronization of the Java code has never been my strongest side, I don’t know what would be causing the error and, most importantly, how can I get rid of it. I’m aware, that Richfaces 4.0 has made a lot of changes to rich:extendedDataTable component, I’ve heard that this was an issue before and now it’s resolved. However, I don’t have time to upgrade the whole application to Richfaces 4.0 (it’s going to be done in phase 2), this is just the small part of the whole project. If there is no way to resolve the issue, described above, then maybe there’s a workaround? Or, perhaps, there are other ways to implement similar kind of search, using plain JSF (provided that it’s are quick enough to implement). I will appreciate any kind of help or advice on that matter. I hope the code is understandable enough, but if not, let me know, I’ll explain further. Thank you in advance, I really appreciate your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:05:30+00:00Added an answer on May 28, 2026 at 6:05 pm

    The problem is concurrent ajax calls to the server. Use the attribute “eventsQueue” in a4j:support. Usually, you should always use “eventsQueue” in any ajax component, with all “eventsQueue” in the same page referencing the same queue, unless you have a very good reason to not doing it.

    Also, you’ll probably want to look into another ajax attribute: “ajaxSingle”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize for the lengthy code. I have a simple question, but I thought
I apologize for asking such a generalized question, but it's something that can prove
I apologize profusely for the incredibly newbish question I'm about to ask, but for
I apologize for the subjectiveness of this question, but I am a little stuck
I apologize for the length of this question, but some background explanation is required.
I apologize since this is rather a n00bish question, but I can't figure this
I apologize in advance if this question seems remedial. Which would be considered more
I apologize in advance if this question seems confused. The behaviour I am seeing
I have what is probably a really dumb grep in R question. Apologies, because
I apologize ahead of time for the length of this question...It's a little involved.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.