You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Eldred Mullany <el...@easypay.co.za> on 2010/03/04 07:58:28 UTC

Display a hashmap using a grid component

Hello everyone

 

I would like to know if anyone has successfully implemented a hash map
through a grid component. How do I display the desired value
(map.get("key")) on my template using a grid component ? Is this
possible in T5.1.0.5? 

 

Thanking you in advance

Eldred Mullany   

 


RE: Display a hashmap using a grid component

Posted by Eldred Mullany <el...@easypay.co.za>.
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:thiagohp@gmail.com] 
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  
<el...@easypay.co.za> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Display a hashmap using a grid component

Posted by Eldred Mullany <el...@easypay.co.za>.
I over complicated it. Thanks

-----Original Message-----
From: Thiago H. de Paula Figueiredo [mailto:thiagohp@gmail.com] 
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  
<el...@easypay.co.za> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Display a hashmap using a grid component

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 08 Mar 2010 10:30:02 -0300, Eldred Mullany  
<el...@easypay.co.za> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Display a hashmap using a grid component

Posted by Eldred Mullany <el...@easypay.co.za>.
Hi Igor 

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?

Secondly the interface ie (GridDataSource) uses an onPrepare()to fetch
the data. 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.

Not sure? 

Thank u 
Eldred


-----Original Message-----
From: Igor Drobiazko [mailto:igor.drobiazko@gmail.com] 
Sent: 04 March 2010 09:05 AM
To: Tapestry users
Subject: Re: Display a hashmap using a grid component

Just create your own implementation of GridDataSource [1] and pass it to
the
Grid component.

[1]
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/grid
/GridDataSource.html

On Thu, Mar 4, 2010 at 7:58 AM, Eldred Mullany
<eldred.mullany@easypay.co.za
> wrote:

> Hello everyone
>
>
>
> I would like to know if anyone has successfully implemented a hash map
> through a grid component. How do I display the desired value
> (map.get("key")) on my template using a grid component ? Is this
> possible in T5.1.0.5?
>
>
>
> Thanking you in advance
>
> Eldred Mullany
>
>
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de/blog

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Display a hashmap using a grid component

Posted by Eldred Mullany <el...@easypay.co.za>.
Thanks Igor. 

-----Original Message-----
From: Igor Drobiazko [mailto:igor.drobiazko@gmail.com] 
Sent: 04 March 2010 09:05 AM
To: Tapestry users
Subject: Re: Display a hashmap using a grid component

Just create your own implementation of GridDataSource [1] and pass it to
the
Grid component.

[1]
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/grid
/GridDataSource.html

On Thu, Mar 4, 2010 at 7:58 AM, Eldred Mullany
<eldred.mullany@easypay.co.za
> wrote:

> Hello everyone
>
>
>
> I would like to know if anyone has successfully implemented a hash map
> through a grid component. How do I display the desired value
> (map.get("key")) on my template using a grid component ? Is this
> possible in T5.1.0.5?
>
>
>
> Thanking you in advance
>
> Eldred Mullany
>
>
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de/blog

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Display a hashmap using a grid component

Posted by Igor Drobiazko <ig...@gmail.com>.
Just create your own implementation of GridDataSource [1] and pass it to the
Grid component.

[1]
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/grid/GridDataSource.html

On Thu, Mar 4, 2010 at 7:58 AM, Eldred Mullany <eldred.mullany@easypay.co.za
> wrote:

> Hello everyone
>
>
>
> I would like to know if anyone has successfully implemented a hash map
> through a grid component. How do I display the desired value
> (map.get("key")) on my template using a grid component ? Is this
> possible in T5.1.0.5?
>
>
>
> Thanking you in advance
>
> Eldred Mullany
>
>
>
>


-- 
Best regards,

Igor Drobiazko
http://tapestry5.de/blog