package com.icefaces.test; import java.util.ArrayList; import java.util.List; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.faces.model.ListDataModel; import com.icesoft.faces.async.render.SessionRenderer; import com.icesoft.faces.component.datapaginator.DataPaginator; public class SearchManager { private ListDataModel list; private DataPaginator dataPaginator; private boolean disableActionButton = false; public static final String USER_PREFIX = "userid"; private static int userCount = 0; private String userId; private boolean resetTable = false; public SearchManager() { list = new ListDataModel(new ArrayList()); for (int i = 0; i < 100; i++) { ((List) list.getWrappedData()).add(new Alert("name" + i)); } // The userId in this case could be anything that makes sense in the context // of the application. This is just a quick, lazy way as it's not really safe // for production. We just want it to be unique to each user. userId = USER_PREFIX + "-" + userCount; userCount++; SessionRenderer.addCurrentSession(userId); } public ListDataModel getAlerts() { return list; } public int getRowsPerPage() { //This doesn't have to be done here. It may make more sense to have it done //somewhere else. if(resetTable) { dataPaginator.gotoFirstPage(); resetTable = false; } return 10; } public DataPaginator getDataPaginator() { return dataPaginator; } public void setDataPaginator(DataPaginator dataPaginator) { this.dataPaginator = dataPaginator; } public boolean isDisableActionButton() { return disableActionButton; } public String doRefresh() { new Thread() { public void run() { try { //Some long running process is spun off into it's own thread Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } //When it's done we want the table to be reset so we set the flag //and issue a render from the server. resetTable = true; SessionRenderer.render(userId); } }.start(); return ""; } }