-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630174
By: rickflair
Hi!
I'd like to convert my ZUL page to JSP, but I have got a problem.
This is my ZUL page:
<window title="Livedata Sorting/Rendering Demo" border="normal">
<zscript><![CDATA[
import org.zkoss.zul.Listitem;
import org.zkoss.zul.event.ListDataEvent;
import org.zkoss.zul.event.ListDataListener;
public class Person {
private String name;
private int nr;
public Person(String name,int nr) { this.name = name; this.nr = nr; }
public String getName() { return this.name; }
public int getNr() { return this.nr; }
}
class MyModel extends ListModelList {
public MyModel(List list) {
super(list, true);
}
public void sort(Comparator cmpr, boolean ascending) {
Collections.sort(getInnerList() , cmpr);
fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
}
}
public class MyModelRenderer implements ListitemRenderer {
public void render( Listitem item, java.lang.Object data ) {
Person itemData = (Person)data;
//item.setAttribute("item",itemData,Component.COMPONENT_SCOPE);
cell = new Listcell(itemData.getName());
cell.setParent(item);
cell = new Listcell(""+itemData.getNr());
cell.setParent(item);
}
}
class MyListListener implements ListDataListener {
public void onChange(ListDataEvent event) {
simple_list.setModel(event.getModel());
simple_list.getPaging().setActivePage(0);
}
}
public class MyComparator implements Comparator {
private boolean ascending;
private int col;
public MyComparator(boolean ascending,int col) {
this.ascending = ascending;
this.col = col;
}
public int compare(Object o1, Object o2) {
Person p1 = (Person)o1;
Person p2 = (Person)o2;
int direction = 0;
switch (col) {
case 0 : direction = p1.getName().compareTo(p2.getName());
break;
case 1 : direction = p2.getName().compareTo(p1.getName());
break;
}
return ascending ? direction : -direction;
}
}
Comparator cmpName_ASC = new MyComparator(true,0);
Comparator cmpName_DESC = new MyComparator(false,0);
Comparator cmpNr_ASC = new MyComparator(true,1);
Comparator cmpNr_DESC = new MyComparator(false,1);
List data = new ArrayList();
for(int i=0; i < 954; i++) {
data.add(new Person("One",i*10+1));
data.add(new Person("Two",i*10+2));
data.add(new Person("Three",i*10+3));
data.add(new Person("Four",i*10+4));
data.add(new Person("Five",i*10+5));
data.add(new Person("Six",i*10+6));
}
MyModel model = new MyModel(data);
model.addListDataListener(new MyListListener());
MyModelRenderer modelRenderer = new MyModelRenderer();
]]></zscript>
<listbox style="margin-bottom: 10px" mold="paging" pageSize="500"
id="simple_list" rows="20">
<listhead>
<listheader label="Nev" sortAscending="${cmpName_ASC}"
sortDescending="${cmpName_DESC}"/>
<listheader label="Sorszam" sortAscending="${cmpNr_ASC}"
sortDescending="${cmpNr_DESC}"/>
</listhead>
</listbox>
<zscript>
simple_list.setModel(model);
simple_list.setItemRenderer(modelRenderer);
</zscript>
</window>
And I converted the ZUL page to JSP, this is the result:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <html> <%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="zuljsp" %> <body> <zuljsp:page zscriptLanguage="java"> <zuljsp:window title="Livedata Sorting/Rendering Demo" border="normal">
<zuljsp:zscript>
import org.zkoss.zul.Listitem;
import org.zkoss.zul.event.ListDataEvent;
import org.zkoss.zul.event.ListDataListener;
public class Person {
private String name;
private int nr;
public Person(String name,int nr) { this.name = name; this.nr = nr; }
public String getName() { return this.name; }
public int getNr() { return this.nr; }
}
class MyModel extends ListModelList {
public MyModel(List list) {
super(list, true);
}
public void sort(Comparator cmpr, boolean ascending) {
Collections.sort(getInnerList() , cmpr);
fireEvent(ListDataEvent.CONTENTS_CHANGED, -1, -1);
}
}
public class MyModelRenderer implements ListitemRenderer {
public void render( Listitem item, java.lang.Object data ) {
Person itemData = (Person)data;
//item.setAttribute("item",itemData,Component.COMPONENT_SCOPE);
cell = new Listcell(itemData.getName());
cell.setParent(item);
cell = new Listcell(""+itemData.getNr());
cell.setParent(item);
}
}
class MyListListener implements ListDataListener {
public void onChange(ListDataEvent event) {
simple_list.setModel(event.getModel());
simple_list.getPaging().setActivePage(0);
}
}
public class MyComparator implements Comparator {
private boolean ascending;
private int col;
public MyComparator(boolean ascending,int col) {
this.ascending = ascending;
this.col = col;
}
public int compare(Object o1, Object o2) {
Person p1 = (Person)o1;
Person p2 = (Person)o2;
int direction = 0;
switch (col) {
case 0 : direction = p1.getName().compareTo(p2.getName());
break;
case 1 : direction = p2.getName().compareTo(p1.getName());
break;
}
return ascending ? direction : -direction;
}
}
Comparator cmpName_ASC = new MyComparator(true,0);
Comparator cmpName_DESC = new MyComparator(false,0);
Comparator cmpNr_ASC = new MyComparator(true,1);
Comparator cmpNr_DESC = new MyComparator(false,1);
List data = new ArrayList();
for(int i=0; i < 954; i++) {
data.add(new Person("One",i*10+1));
data.add(new Person("Two",i*10+2));
data.add(new Person("Three",i*10+3));
data.add(new Person("Four",i*10+4));
data.add(new Person("Five",i*10+5));
data.add(new Person("Six",i*10+6));
}
MyModel model = new MyModel(data);
model.addListDataListener(new MyListListener());
MyModelRenderer modelRenderer = new MyModelRenderer();
</zuljsp:zscript>
<zuljsp:listbox style="margin-bottom: 10px" mold="paging" pageSize="500"
id="simple_list" rows="20">
<zuljsp:listhead>
<zuljsp:listheader label="Nev" sortAscending="${cmpName_ASC}"
sortDescending="${cmpName_DESC}"/>
<zuljsp:listheader label="Sorszam" sortAscending="${cmpNr_ASC}"
sortDescending="${cmpNr_DESC}"/>
</zuljsp:listhead>
</zuljsp:listbox>
<zuljsp:zscript>
simple_list.setModel(model);
simple_list.setItemRenderer(modelRenderer);
</zuljsp:zscript>
</zuljsp:window>
</zuljsp:page>
</body>
</html>
But when I deploy the JSP page and have a look at it, the webpage doesn't appear and I get this message:
org.apache.jasper.JasperException: org.zkoss.zk.ui.UiException:
javax.servlet.jsp.JspException: javax.servlet.jsp.JspException:
javax.servlet.jsp.JspException: javax.servlet.jsp.JspException:
java.lang.NullPointerException
I think the problem is at these rows:
<zuljsp:listheader label="Nev" sortAscending="${cmpName_ASC}"
sortDescending="${cmpName_DESC}"/>
<zuljsp:listheader label="Sorszam" sortAscending="${cmpNr_ASC}"
sortDescending="${cmpNr_DESC}"/>
How must I convert these rows?
Thank You!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630413
By: robbiecheng
Have you tried the latest version of ZK JSP TAG 1.1?
I've tested your code using ZK JSP TAG 1.1, and it works well.
Please try ZK JSP TAG 1.1.
/Robbie
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630823
By: rickflair
Interesting, I tried the ZK JSP 1.1, but I got the next message:
org.apache.jasper.JasperException: org.zkoss.zk.ui.UiException:
javax.servlet.jsp.JspException: java.lang.NoClassDefFoundError:
org/zkoss/zk/ui/util/Composer
Where is this class? In which jar?
Thanks!
rf
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630841
By: rickflair
Hmm, I downloaded the ZK 3.0 and I find this class there.
I think I have got a release candidate version...
Thanks!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4630896
By: rickflair
Hi!
Yes, i don't get error message (at normal ZK 3.0), but the columns are not sortable, I cannot click the header to sort.
I think, the ZK interpreter doesn't compile correctly these lines:
<zuljsp:listheader label="Nev" sortAscending="${cmpName_ASC}"
sortDescending="${cmpName_DESC}" />
<zuljsp:listheader label="Sorszam" sortAscending="${cmpNr_ASC}"
sortDescending="${cmpNr_DESC}" />
I have to write a '$' character in a ZUL page, but I think I must write other character in JSP?
Or how can i add these in <zscript> tag?
Thanks!
rf
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4632685
By: robbiecheng
Of course, zscript is supported in JSP TAG.
Try this,
<zuljsp:zscript>
Comparator asc = new ListitemComarator(-1, true, true);
Comparator dsc = new ListitemComarator(-1, false, true);
</zuljsp:zscript>
/Robbie
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4633258
By: rickflair
Hi Robbie!
Thank you, but I mean how can I assign the created comparator to header (not in <listheader> tag but in <zscript> tag)?
In my sample how can I assign the cmpName_ASC comparator to the first header in the <zscript> tag?
Thanks!
rf
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4633849
By: robbiecheng
Hi rf,
Try this,
<zscript>
void setComparator(){
Comparator cmpName_ASC = new MyComparator(true,0);
header1.setSortAscending(cmpName_ASC);
}
</zscript>
<zuljsp:listheader id="header1" label="Nev"/>
/Robbie
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4633894
By: rickflair
Thank You Robbie! You are a decent chap!
It was a big help for me!
rf
Asked: 2007-11-18 22:14:27 +0800
Seen: 303 times
Last updated: Nov 20 '07