Hi Thiago
Sorry I still don't understand how to implement this.
My search page I have
public class Search {
@Property
private MapGridDataSource list;
....
Object onSuccess () {
//create a map
Map<Integer, String> list = new HashMap<Integer, String>();
//return a list
list.put(1, "Row 1");
list.put(2, "Row 2");
list.put(3, "Row 3");
//create an instance of MapGridDataSource and pass the map to it
this.list = new MapGridDataSource(list);
return this.searchResultsZone.getBody();
}
<!--My template page -->
My search.tml page
<table class="tbl" t:type="grid" t:source="list" t:row="current"
t:inplace="literal:true" border="0">
Then in my template I get back a table header called "empty" and table cell
called "false". Then I pass my list through my custom MapGridDataSource class,
however I still get the above result?
My MapGridDataSource class:
public class MapGridDataSource implements GridDataSource {
private final List list;
@SuppressWarnings("unchecked")
public MapGridDataSource(final Map map) {
Defense.notNull(map, "map");
// Copy the collection so that we can sort it without disturbing the
// original
list = CollectionFactory.newList(map);
}
/*
* (non-Javadoc)
*
* @see org.apache.tapestry5.grid.GridDataSource#getAvailableRows()
*/
public int getAvailableRows() {
// TODO Auto-generated method stub
return list.size();
}
/*
* (non-Javadoc)
*
* @see org.apache.tapestry5.grid.GridDataSource#getRowType()
*/
/*
* (non-Javadoc)
*
* @see org.apache.tapestry5.grid.GridDataSource#prepare(int, int,
* java.util.List)
*/
@SuppressWarnings("unchecked")
public void prepare(int startIndex, int endIndex, List<SortConstraint>
sortConstraints) {
for (SortConstraint constraint : sortConstraints) {
final ColumnSort sort = constraint.getColumnSort();
if (sort == ColumnSort.UNSORTED)
continue;
final PropertyConduit conduit =
constraint.getPropertyModel().getConduit();
final Comparator valueComparator = new Comparator<Comparable>() {
public int compare(Comparable o1, Comparable o2) {
// Simplify comparison, and handle case where both are
// nulls.
if (o1 == o2)
return 0;
if (o2 == null)
return 1;
if (o1 == null)
return -1;
return o1.compareTo(o2);
}
};
final Comparator rowComparator = new Comparator() {
public int compare(Object row1, Object row2) {
Comparable value1 = (Comparable) conduit.get(row1);
Comparable value2 = (Comparable) conduit.get(row2);
return valueComparator.compare(value1, value2);
}
};
final Comparator reverseComparator = new Comparator() {
public int compare(Object o1, Object o2) {
int modifier = sort == ColumnSort.ASCENDING ? 1 : -1;
return modifier * rowComparator.compare(o1, o2);
}
};
// We can freely sort this list because its just a copy.
Collections.sort(list, reverseComparator);
}
}
/**
* @return the list
*/
public List getList() {
return list;
}
/**
* @param list
* the list to set
*/
public void setList(List <?> list) {
this.list = list;
}
/**
* Returns the type of the first element in the list, or null if the list is
* empty.
*/
public Class getRowType() {
return list.isEmpty() ? null : list.get(0).getClass();
}
public Object getRowValue(int index) {
return list.get(index);
}
What have I done incorrectly ?
Many thanks Eldred
-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:[email protected]]
Sent: 08 March 2010 03:38 PM
To: Tapestry users
Subject: Re: Display a hashmap using a grid component
On Mon, 08 Mar 2010 10:30:02 -0300, Eldred Mullany
<[email protected]> wrote:
> I am at a loss here, you make it sound easy. First of all how to I
> implement own GridDataSource class and how to I tell tapestry to use it,
> a contribution method I need to add to my AppModule?
You pass an instance of your GridDataSource implementation to the source
parameter of Grid.
> Secondly the interface ie (GridDataSource) uses an onPrepare()to fetch
> the data.
Events are just triggered in page, componente and mixin classes.
> I would then think I have to do some sort of cast / conversion
> to list from a map that I pass to it as a parameter.
Using a GridDataSource doesn't require a list. Grid's source parameter
receives a GridDataSource. Lists are converted automatically.
--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da
Informação Ltda.
http://www.arsmachina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]