Here is a more recent version of the code. This time I have the query return a
List of maps for an HQL query.
I just override get id and it works. Try this more recent version. Are you
using Seam 2.0.x?
I have not seen too much interest in my method. If people like the technique
employed, I can post an example when I get some time.
|
| import java.io.IOException;
| import java.io.Serializable;
| import java.util.ArrayList;
| import java.util.HashMap;
| import java.util.List;
| import java.util.Map;
|
| import javax.faces.context.FacesContext;
|
| import org.ajax4jsf.model.DataVisitor;
| import org.ajax4jsf.model.ExtendedDataModel;
| import org.ajax4jsf.model.Range;
| import org.ajax4jsf.model.SequenceRange;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.log.Log;
|
| import com.xxx.ui.Idable;
|
| public abstract class BaseExtendedDataModel
extends ExtendedDataModel implements BaseExtendedDataModelDAO{
|
| private @Logger Log log;
|
| int rowNum=-1;
|
| public int getRowNum()
| {
| return ++rowNum;
| }
|
| public List listRow;
|
| private ID currentId;
| private Map wrappedData = new HashMap();
| private List wrappedKeys;
| private Long rowCount; // better to buffer row count locally
|
| public abstract Long getCount();
| public abstract List getList(Integer firstRow, Integer maxResults);
| public abstract T findById(ID id);
|
| public ID getId(T row)
| {
| Idable idable = (Idable) row;
| ID id = (ID) idable.getId();
| return id;
| }
|
| public void wrap(FacesContext context, DataVisitor visitor, Range
range, Object argument, List list) throws IOException
| {
| wrappedKeys = new ArrayList();
| wrappedData = new HashMap();
| for (T row : list)
| {
| ID id = getId(row);
| wrappedKeys.add(id);
| wrappedData.put(id, row);
| visitor.process(context, id, argument);
| }
| }
|
| public boolean hasById(ID id)
| {
| for (T row : listRow)
| {
| ID rowId = getId(row);
| if (rowId.equals(id))
| {
| return true;
| }
| }
| return false;
| }
|
| @Override
| public void walk(FacesContext context, DataVisitor visitor, Range
range, Object argument) throws IOException
| {
| int firstRow = ((SequenceRange) range).getFirstRow();
| int maxResults = ((SequenceRange) range).getRows();
| log.info("("+firstRow +", "+ maxResults+")");
| wrap(context, visitor, range, argument, getList(firstRow,
maxResults));
| }
|
| /*
| * This method normally called by Visitor before request Data Row.
| */
| @Override
| public void setRowKey(Object key)
| {
| this.currentId = (ID) key;
| }
|
| @Override
| public int getRowCount()
| {
| if(rowCount == null)
| return (rowCount = this.getCount()).intValue();
| else
| return rowCount.intValue();
| }
|
| @Override
| public boolean isRowAvailable()
| {
| if (currentId == null) {
| return false;
| } else {
| return hasById(currentId);
| }
| }
|
| /**
| * This is main way to obtain data row. It is intensively used by
framework.
| * We strongly recommend use of local cache in that method.
| */
| @Override
| public Object getRowData() {
| if (currentId == null) {
| return null;
| } else {
| T ret = wrappedData.get(currentId);
| if (ret == null) {
| ret = this.findById(currentId);
| wrappedData.put(currentId, ret);
| return ret;
| } else {
| return ret;
| }
| }
| }
|
|
| // Unused rudiment from old JSF staff.
| @Override public int getRowIndex() { throw new
UnsupportedOperationException(); }
| @Override public void setRowIndex(int rowIndex) { throw new
UnsupportedOperationException(); }
| @Override public Object getWrappedData() { throw new
UnsupportedOperationException(); }
| @Override public void setWrappedData(Objec