Creating a BeanTable from a Collection of java beans

View: New views
6 Messages — Rating Filter:   Alert me  

Creating a BeanTable from a Collection of java beans

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all! I would like to  know how to use wicket rad to display a table with a given collection of Beans and how to specify the attributes to show in every column.
Thanks in advance,
Wadi

Re: Creating a BeanTable from a Collection of java beans

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
As you might already have worked out partially already, you should use one of the PropertyTable implementations, such as AjaxBeanPropertyTable.
Apart from calling the constructor, you also need to call the init() method with an implementation of a PropertyTableProvider (which is responsible of the retrieving of the collection of beans, a default impl is available in DefaultBeanPropertyTableProvider for JPA, although there is an inheritance bug in this, which has been fixed in SVN, but is not yet released).

Finally, your beans getter-methods should have annotations from the org.wicketrad.propertytable.annotation package, such as @LabelProperty for just a simple label, @BookmarkableLinkProperty if you want the property to be displayed as a bookmarkable link in the table, or a @BeanLinkProperty for a stateful link that will pass in the current bean itself as an argument to the Page it links to.

Hope that helps!

wadi wrote:
Hi all! I would like to  know how to use wicket rad to display a table with a given collection of Beans and how to specify the attributes to show in every column.
Thanks in advance,
Wadi

Re: Creating a BeanTable from a Collection of java beans

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks! But I don't understand how should I set my beans collection, should I do myPropertyTable.setModel(myCollectionOfBean); ?
Thanks a lot again!
Wadi

Re: Creating a BeanTable from a Collection of java beans

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

No, that will not do anything, as the propertytable gets its data from the IPropertyTableProvider implementation, more specifically it's public Iterator<IPropertyCollection> iterator(int first, int results); method.
The interface is an extension of IDataProvider which is in Wicket's core framework.
Basically when you page through a table that is pageable, as a PropertyTable, the iterator() and count() methods will be called, the count() method to see how many results there are, the iterator() method to get a subset of the result to display (for instance indexes 0 to 10).

wadi wrote:
Thanks! But I don't understand how should I set my beans collection, should I do myPropertyTable.setModel(myCollectionOfBean); ?
Thanks a lot again!
Wadi

Re: Creating a BeanTable from a Collection of java beans

by wfaler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

..I think the easiest route is to extend the AbstractPropertyTableProvider class, if you are using beans.

Re: Creating a BeanTable from a Collection of java beans

by wadi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks!