0

listbox itemrenderer

asked 2006-05-12 01:09:51 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725129

By: michaelkmb

According to release note of 1.2.0, the alignment of header and body of grid, listbox and tree are improved to handle all known extremely cases. However, i found my listbox not rendered correctly if itemrenderer is usef. I'm not sure it is due to my coding error or Zk's issue. Please advise.

Try following page and see the different.

Michael

<window>
<zscript>
String[] data = {"1","2","3"};
dataModel = new SimpleListModel(data);

public class dataRenderer implements ListitemRenderer {

public void render(Listitem item, Object data) throws Exception {
for (int j=0;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
}

}

daRender = new dataRenderer();

</zscript>
<label value="listbox with itemRenderer" /> <listbox id="lb2" model="${dataModel}" itemRenderer="${daRender}" >
<listhead id="lh2">
<listheader label="col1" width="100px" />
<listheader label="col2" width="100px" />
<listheader label="col3" width="100px" />
<listheader label="col4" width="100px" />
<listheader label="col5" width="100px" />
<listheader label="col6" width="100px" />
</listhead>
</listbox>
<label value="general listbox" />
<listbox id="lb1" >
<listhead id="lh1">
<listheader label="col1" width="100px" />
<listheader label="col2" width="100px" />
<listheader label="col3" width="100px" />
<listheader label="col4" width="100px" />
<listheader label="col5" width="100px" />
<listheader label="col6" width="100px" />
</listhead>
</listbox>

<zscript>
for (int i=0;i@lt3;i++) {
item = new Listitem();
for (int j=0;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
item.setParent(lb1);
}
</zscript>
</window>

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2006-05-12 02:20:58 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725165

By: michaelkmb

It seems that to make the listbox (with itemRenderer) align properly, following should be added:

1. an extra <listheader> need to be added (with width say "5px"). (since an extra field is generated in the listbox body if model is used)

2. set the width of listbox.

Following is a modified version.

<window>
<zscript>
String[] data = {"1","2","3"};
dataModel = new SimpleListModel(data);

public class dataRenderer implements ListitemRenderer {

public void render(Listitem item, Object data) throws Exception {
for (int j=0;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
}

}

daRender = new dataRenderer();

</zscript>
<label value="listbox with itemRenderer" /> <listbox id="lb2" model="${dataModel}" itemRenderer="${daRender}" >
<listhead id="lh2">
<listheader label="" width="5px"/>
<listheader label="col1" width="100px" />
<listheader label="col2" width="100px"/>
<listheader label="col3" width="100px"/>
<listheader label="col4" width="100px"/>
<listheader label="col5" width="100px"/>
<listheader label="col6" width="100px" />
</listhead>
</listbox>
<label value="listbox with dynamic data" /> <listbox id="lb1" width="650px" >
<listhead>
<listheader label="col1" width="100px"/>
<listheader label="col2" width="100px"/>
<listheader label="col3" width="100px"/>
<listheader label="col4" width="100px"/>
<listheader label="col5" width="100px"/>
<listheader label="col6" width="100px"/>
</listhead>
</listbox>

<zscript>
for (int i=0;i@lt3;i++) {
item = new Listitem();
for (int j=0;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
item.setParent(lb1);
}
</zscript>

</window>

Michael

link publish delete flag offensive edit

answered 2006-05-12 02:25:05 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725169

By: nobody

You need column 7 for your list header since you've got 7 columns rendering.
The Listitem itself come with one cell to begin with.

link publish delete flag offensive edit

answered 2006-05-12 03:02:36 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725196

By: nobody

maybe it should be implemented in ZK such that an empty header automatically shows (or flagged to show through attributes) when there are more columns in rows than headers.

link publish delete flag offensive edit

answered 2006-05-12 04:54:05 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725262

By: michaelkmb

And extra column is added only for live-data listbox. (i.e. "model" attribute
specified)

Michael

link publish delete flag offensive edit

answered 2006-05-12 06:25:21 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725310

By: henrichen

The reason is the number of Listheader is not consistent with the number of Listcell. And why is that? In ZK's Java API doc, about the method render() of
ListitemRenderer:

http://zk1.sourceforge.net/javadoc/1.2.0/zul/com/potix/zul/html/ListitemRenderer
.html

"Parameters:
item - the listitem to render the result. Note: when this method is called, the listitem has exactly one Listcell (with an empty label). If you want to render to multiple column, you have to create the second and following Listcell."

Your render() code append 6 kids onto the Listitem and make it a 7 kids parent while you prepare only 6 Listheaders and that cause the alignment issue.

/henri


link publish delete flag offensive edit

answered 2006-05-12 06:33:25 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725312

By: henrichen

This code should work ok.

<window>
<zscript>
String[] data = {"1","2","3"};
dataModel = new SimpleListModel(data);

public class dataRenderer implements ListitemRenderer {

public void render(Listitem item, Object data) throws Exception {

Iterator it = item.getChildren().iterator(); int j=0; if (it.hasNext()) { Listcell cell = it.next(); cell.setLabel("col-0"); j=1; //j start from 1 }

for (;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
}

}

daRender = new dataRenderer();

</zscript>
<label value="listbox with itemRenderer" /> <listbox id="lb2" model="${dataModel}" itemRenderer="${daRender}" >
<listhead id="lh2">
<listheader label="col1" width="100px" />
<listheader label="col2" width="100px" />
<listheader label="col3" width="100px" />
<listheader label="col4" width="100px" />
<listheader label="col5" width="100px" />
<listheader label="col6" width="100px" />
</listhead>
</listbox>
<label value="general listbox" />
<listbox id="lb1" >
<listhead id="lh1">
<listheader label="col1" width="100px" />
<listheader label="col2" width="100px" />
<listheader label="col3" width="100px" />
<listheader label="col4" width="100px" />
<listheader label="col5" width="100px" />
<listheader label="col6" width="100px" />
</listhead>
</listbox>

<zscript>
for (int i=0;i@lt3;i++) {
item = new Listitem();
for (int j=0;j@lt6;j++) {
cell = new Listcell("col-"+j);
cell.setParent(item);
}
item.setParent(lb1);
}
</zscript>
</window>

/henri

link publish delete flag offensive edit

answered 2006-05-12 06:38:48 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725318

By: henrichen

The original spec. is not elegant that carry an extra Listcell in Listitem when
render() method of ListitemRenderer is called. I will file a Feature-Request to change it to carry no extra Listcell.

/henri

link publish delete flag offensive edit

answered 2006-05-12 06:42:40 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3725322

By: henrichen

It is a not good idea to let ZK automatically generate extra Listheader for extra Listcell. It is easy to confuse and suprise the developer.

/henri


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-05-12 01:09:51 +0800

Seen: 1,085 times

Last updated: May 12 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More