-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys... I'm having problem with this code:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window title="Categoria" border="normal" apply="${categoriaController}">
<listbox id="list" multiple="false" rows="10" model="@{model.categorias}" selectedItem="@{model.selectedCategoria}">
<listhead>
<listheader label="Codigo" width="50px" sort="auto"/>
<listheader label="Nome" sort="auto"/>
</listhead>
<listitem self="@{each=categoria}">
<listcell label="@{categoria.id}"/>
<listcell label="@{categoria.nome}"/>
</listitem>
</listbox>
</windows>
The databinding is working fine, but I'm having problems with "Sorting"...
SEVERE: >>java.lang.ClassCastException:
at org.zkoss.zul.ListitemComparator.compare(ListitemComparator.java:252)
I implemented the Comparable<Categoria> interface and it worked, but I don't have control, in my POJO about what colum is pressed... So I get order only by name or by id... How does ZK work with sort and databinding? Have I do implement other interface?? I supose if ZK get the values from my POJO, it should use the column type to sort... In my case the field "name" is a String, and String implements the Comparable interface... Shouldn't ZK call the String.compareTo() when I try sorting? I'm not sorting Categoria objects directy, but sorting these objects by its fields....
Please help me to solve this problems!
Hi erick,
To be able to allow the onSort() method to be called by each Listheader, you will need to implement a controller which extends Composer (GenericForwardComposer) interface. In other words, you have control to which column pressed. For example in my small test:
ListBOx1Composer.java:
public class ListBOx1Composer extends GenericForwardComposer { ...other methods... public void onSort$lh_name() { System.out.println("ONSORT_CALLED on listheader lh_name."); } public void onSort$lh_id() { System.out.println("ONSORT_CALLED on listheader lh_id."); } }
sort.zul:
<window title="Mah Window" border="normal" width="200px"> <listbox apply="ListBOx1Composer"> <listhead> <listheader id="lh_name" label="name" sort="auto" /> <listheader id="lh_id" label="id" sort="auto" /> </listhead> </listbox> </window>
Then in your each onSort method you can then use different Comparators to your list model.
Hope this helps.
Hi robertlee,
Thank you for the help... I will try do it.... But I think it should be a interesting feature....
When I put:
<listitem self="@{each=categoria}"> <listcell label="@{categoria.id}"/> <listcell label="@{categoria.nome}"/> </listitem>
Can I post it as a feature request??
[]s
Hi,
I'm opening this track again.... The option : implements a Generic Forward Composer doesn't work:
I implemented the onSort method and it's working.... But as exception is trowed always:
"cannot cast do java.lang.Comparable"
I supose that:
If I'm ordering the objects in my ListBOx1Composer, my bean doesn't need implements Comparable, because the method compareTo() isn't called...
But ZK is calling this method.... So, the list is ordered, but I get this exception....
Is it a bug?? How can I, using listModel, have my list ordered, for each field?
[]s
hi Erick,
if you look at the developer guide, it actually gave a better way to assign the comparator.(using sortAscending and sortDescending properties) Also if you remove the sort="auto", your exception will go away.
http://docs.zkoss.org/wiki/Grids,_Trees_and_Listbox#The_sortAscending_and_sortDescending_Properties
Hope this helps.
Asked: 2008-12-24 15:26:47 +0800
Seen: 459 times
Last updated: Jan 07 '09