visitChildren is so cool

On 6/12/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
here is a quick and easy way to do ajax headers toolbar for datatable. it modifies all regular links produced by the regular toolbar to be ajax links with fallback.

package wicket.extensions.ajax.markup.html.repeater.data.table ;

import wicket.Component;
import wicket.ajax.AjaxEventBehavior;
import wicket.ajax.AjaxRequestTarget;
import wicket.ajax.IAjaxCallDecorator;
import wicket.ajax.calldecorator.CancelEventIfNoAjaxDecorator ;
import wicket.extensions.markup.html.repeater.data.sort.ISortStateLocator;
import wicket.extensions.markup.html.repeater.data.table.DataTable;
import wicket.extensions.markup.html.repeater.data.table.HeadersToolbar ;
import wicket.markup.html.link.Link;

public class AjaxFallbackHeadersToolbar extends HeadersToolbar
{
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    public AjaxFallbackHeadersToolbar(DataTable table, ISortStateLocator stateLocator)
    {
        this(table, stateLocator, null);
    }


    public AjaxFallbackHeadersToolbar(DataTable table, ISortStateLocator stateLocator,
            final IAjaxCallDecorator decorator)
    {
        super(table, stateLocator);
        table.setOutputMarkupId(true);
       
        visitChildren(new IVisitor()
        {

            public Object component(Component component)
            {
                if (component instanceof Link) {
                    Link link = (Link)component;
                    link.add(new AjaxEventBehavior("onclick")
                    {
   
                        private static final long serialVersionUID = 1L;
   
                        protected void onEvent(AjaxRequestTarget target)
                        {
                            ((Link)getComponent()).onClick();
                            onAjaxClick(target);
                        }
   
                        protected IAjaxCallDecorator getAjaxCallDecorator()
                        {
                            return new CancelEventIfNoAjaxDecorator(decorator);
                        }
   
                    });
   
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                } else {
                    return CONTINUE_TRAVERSAL;
                }
            }

        });

    }


    protected void onAjaxClick(AjaxRequestTarget target)
    {
        target.addComponent(getTable());
    }


}

-Igor



On 6/11/06, lu dongping < [EMAIL PROTECTED]> wrote:
I added two Ajax*.javas to make ajax happy.
and changed the final onClick method to non-final. because AjaxOrderByLink have to override it.  ( perhaps I should not do it this way)
And I added another ListSortStateLocator to wrapper a simple List as a ISortStateLocator, then PageableListView/ListView can use  AjaxOrderByLink too .


The original example is like this:

 SortableContactDataProvider dp = new SortableContactDataProvider();
 final DataView dataView = new DataView("oir", dp)
......
datacontainer.add(new OrderByBorder("orderByFirstName", "firstName", dp)
                {
                        protected void onSortChanged()
                        {
                                dataView.setCurrentPage(0);
                        }
                });

now use ajax is as simple as this :

datacontainer.add(new AjaxOrderByBorder("orderByFirstName", "firstName", dp, dataView)
                {
                        protected void onSortChanged()
                        {
                                dataView.setCurrentPage(0);
                        }
                });


and also, to sort a PageableListView :   // borrowed by PageablePage example

 WebMarkupContainer datacontainer = new WebMarkupContainer("data");
                datacontainer.setOutputMarkupId(true);
                add(datacontainer);

                final List list = Arrays.asList(names);
                ISortStateLocator ssl = new ListSortStateLocator(list){
                    protected void sortList(List list,String name, int order){
                        // because I'm lazy, here I just reverse the list.
                        Collections.reverse(list);
                    }
                };

                final PageableListView listview = new PageableListView("rows", list, 10)
                {
                        protected void populateItem(ListItem item)
                        {
                                item.add(new Label("name", item.getModelObjectAsString()));
                        }
                };

                datacontainer.add(listview);

                datacontainer.add(new AjaxOrderByBorder("orderByName", "name", ssl, listview)
                {
                        protected void onSortChanged()
                        {
                                listview.setCurrentPage(0);
                        }
                });



On 6/11/06, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
i checked this into 2.0 trunk earlier today, but im having trouble backporting to 1.2

see DefaultAjaxFallbackDatatable

only supports sorting so far, when i have time i will take a look at your paging patch.

-Igor



On 6/10/06, lu dongping < [EMAIL PROTECTED]> wrote:
I'll try to fix this.


On 6/10/06, Igor Vaynberg < [EMAIL PROTECTED]> wrote:
yep, we dont have support for that yet. datatable and friends were built way before we had ajax support. what we need to do is create an ajaxified order by link and create factory on the headerstoolbar to generate links just like the tabbedpanel does.

this is a bit of work and i dont know if someone has the time to do it right now.

you can either create a bug for it and we will get to it when we can, or do the refactor yourself and provide us with a patch.

i know martijn is interested in working on this but i am unsure about his availability.

-Igor


On 6/9/06, Stefan Kanev < [EMAIL PROTECTED]> wrote:
Hi. Is there a quick way to implement the sorting of the DataTable with AJAX, or should I go rewriting everything from the OrderByLink to the HeadersToolbar?



_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user







_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to