users@woodstock.java.net

Re: Dynamic table sorting question

From: Jianbo <jzstancil_at_yahoo.com>
Date: Thu, 21 Feb 2008 05:54:46 -0800 (PST)

Hi Dan,
Thanks for your reply.
I tried more things again following your suggestion, but failed again and
again.

Here is one of the things I tried:

I created my own MyTableSorter (but it doesn't do anything except printing
out some info):

         public class MyTableSorter extends BasicTableDataSorter
        {
                @Override
                public SortCriteria[] getSortCriteria()
                {
                        System.out.println("Sorter: getSortCriteria");
                        return super.getSortCriteria();
                }

                @Override
                public Locale getSortLocale()
                {
                        System.out.println("Sorter: getSortLocale");
                        return super.getSortLocale();
                }

                @Override
                public void setSortCriteria(SortCriteria[] arg0)
                {
                        System.out.println("Sorter: setSortCriteria");
                        super.setSortCriteria(arg0);
                }

                @Override
                public void setSortLocale(Locale arg0)
                {
                        System.out.println("Sorter: setSortLocale");
                        super.setSortLocale(arg0);
                }

                @Override
                public RowKey[] sort(TableDataProvider arg0, RowKey[] arg1) throws
DataProviderException
                {
                        System.out.println("Sorter: sort ");
                        return super.sort(arg0, arg1);
                }
        }

and I set it to the TableRowGroup (in Dynamic.java):
             rowGroup.setTableDataSorter(new MyTableSorter());

When the table (dynamicTable.jsp, DynamicTableBean.java .....) is loaded,
MyTableSorter's getSortCriteria() and sort(...) are called. But there is no
SortCriteria yet, so sort(...) doesn't do anything. So far so good.

But, when I click on column headers, the table is sorted by some other
sorter instead of MyTableSorter. MyTableSorter's getSortCriteria() and
sort(...) are never called again.

What happened? What did I miss?


I tried to figure out the real sorter being used; so I changed (in
Dynamic.java)
    TableRowGroup rowGroup = new TableRowGroup();
to
   MyTableRowGroup rowGroup = new MtTableRowGroup();

Where MyTableRowGroup doesn't do anything except printing out the sorter
object:
     public class MyTableRowGroup extends TableRowGroup {
        @Override
        public TableDataSorter getTableDataSorter()
        {
                TableDataSorter sorter = super.getTableDataSorter();
                System.out.println("Which sorter: " + sorter);
                return sorter;
        }
    }


When the table first loaded, it tells me that MyTableSorter is the sorter in
the rowGroup. So far so good.
But, when I click on a column header to sort, I get an exception:

exception

javax.servlet.ServletException:
com.lancope.jsf.tableBeans.util.Dynamic$MyTableRowGroup
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)

root cause

java.lang.InstantiationException:
com.lancope.jsf.tableBeans.util.Dynamic$MyTableRowGroup
        java.lang.Class.newInstance0(Class.java:335)
        java.lang.Class.newInstance(Class.java:303)

com.sun.faces.application.StateManagerImpl.newInstance(StateManagerImpl.java:616)

com.sun.faces.application.StateManagerImpl.restoreTree(StateManagerImpl.java:705)

com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:204)

javax.faces.application.StateManagerWrapper.restoreView(StateManagerWrapper.java:178)

com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:318)
        com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:176)
        com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:104)
        com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)

I am very lost.
Can you tell me what I did wrong and what I missed?
Really appreciate your help.
jianbo



Dan Labrecque wrote:
>
> I don't have any examples for you. However, BasicTableDataSorter tests
> if objects implement Comparator, first. If the sorted object implements
> this interface, you can control the sort. Otherwise, you could extend
> BasicTableDataSorter and provide that to TableRowGroup.
>
> Dan
>
> Jianbo wrote:
>> I have just started trying Woodstock dynamic table component. I am
>> using the /dynamicTable/ example which has a list of /Name/s.
>> Everything works fine with default sorting feature. But I want to do
>> my own sorting with my own comparator.
>>
>> For example, I want to sort last name column in a different way (e.g.
>> sort by the last letter of last name. I know it is crazy but I just
>> want to know how to do it.)
>>
>> I have tried several things: subclass /ObjectArrayDataProvider/;
>> subclass /BasicTableDataSorter/ and set it to my /TableRowGroup/; etc.
>> But none or them works.
>>
>> I have searched and searched but didn't find an example.
>>
>> Please help me.
>> Thanks,
>> jianbo
>> ------------------------------------------------------------------------
>> View this message in context: Dynamic table sorting question
>> <http://www.nabble.com/Dynamic-table-sorting-question-tp15592362p15592362.html>
>> Sent from the Project Woodstock - Users mailing list archive
>> <http://www.nabble.com/Project-Woodstock---Users-f26168.html> at
>> Nabble.com.
>
>
>

-- 
View this message in context: http://www.nabble.com/Dynamic-table-sorting-question-tp15592362p15611834.html
Sent from the Project Woodstock - Users mailing list archive at Nabble.com.