-
1. Re: Seam with richfaces extended data table
herberson Jul 12, 2010 10:29 PM (in response to daxxy)Hi,
I already faced the same issue and found a solution.
First you have understand that data passed from Seam to rich:extendedDataTable must be a DataModel class and unfortunately we can't use a java.util.List annoted with @DataModel.
After a couple of hours of debuging RichFaces and Seam source codes I discover that I have to use a object of class org.richfaces.model.ExtendedTableDataModel and to instantiate that I too have to use a object and this one must be a intance of interface org.richfaces.model.DataProvider.
So to instantiate a ExtendedTableDataModel i had to provide a implementation of class DataProvider.
Here a example code of DataProvider implementation:
import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.Comparator; import java.util.List; import org.apache.commons.beanutils.PropertyUtils; import org.richfaces.model.DataProvider; public class MyDataProvider<T> implements DataProvider<T> { private static final long serialVersionUID = -4599358104308291613L; private List<T> data; private String keyProperty; public MyDataProvider(List<T> data, String keyProperty) { this.data = data; this.keyProperty = keyProperty; } public T removeItem(T item) { return removeItemByKey(getKey(item)); } public T removeItemByKey(Object key) { T removedItem = null; T iterItem = null; for (int iItem = 0; iItem < getRowCount(); iItem++) { iterItem = data.get(iItem); if ( getKey(iterItem).equals(key) ) { removedItem = iterItem; data.remove(iItem); break; } } return removedItem; } public void orderItemsBy(final String propertyName) { Collections.sort(data, new Comparator<T>() { @SuppressWarnings("unchecked") public int compare(T o1, T o2) { int comp = -1; if (o1 == null || o2 == null) { comp = 0; } else { Object valueO1 = getPropertyValue(o1, propertyName); Object valueO2 = getPropertyValue(o2, propertyName); if (valueO1 == null || valueO2 == null) { comp = 0; } else if (valueO1 instanceof Comparable && valueO2 instanceof Comparable) { comp = ((Comparable)valueO1).compareTo(valueO2); } else { comp = valueO1.toString().compareTo(valueO2.toString()); }//end if }//end if return comp; }//end method }); } public void clear() { data.clear(); } public boolean isEmpty() { return (data == null || data.isEmpty()); } public void addItem(T item) { data.add(item); } private Object getPropertyValue(T item, String propertyName) { Object k; try { k = PropertyUtils.getProperty(item, getKeyProperty()); } catch (IllegalAccessException e) { k = null; } catch (InvocationTargetException e) { k = null; } catch (NoSuchMethodException e) { k = null; } return k; } public T getItemByKey(Object key) { for (T item : data) { if (key.equals(getKey(item))) { return item; } } return null; } public List<T> getItemsByRange(int firstRow, int endRow) { return data.subList(firstRow, endRow); } public Object getKey(T item) { return getPropertyValue(item, getKeyProperty()); } public int getRowCount() { return data.size(); } public List<T> getData() { return data; } public void setData(List<T> data) { this.data = data; } public String getKeyProperty() { return keyProperty; } public void setKeyProperty(String keyProperty) { this.keyProperty = keyProperty; } }
Herberson
-
2. Re: Seam with richfaces extended data table
yahawari Jul 17, 2010 11:03 PM (in response to daxxy)u need to test the performance of this component. richfaces extendedDataTable and tree components should be used with care. they DO have performance problems.