0

checkbox多选框选择问题

asked 2009-10-10 02:48:03 +0800

ring gravatar image ring
99 1

如题:动态获取带有checkbox的列表时,发现点着点着,之前已经选中的都变成不选中了,而且还有偶尔出现只能单选,而不能多选的情况,不知哪位高手可以帮忙解决下?
页面ZUL代码如下:
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window apply="com.window.testCheckboxWindow">

<listbox id="box" width="250px" rows="20" fixedLayout="true"
multiple="true" checkmark="true">
<listhead>
<listheader label="Name"/>
</listhead>
</listbox>
</window>
</zk>

JAVA代码如下:
package com.window;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.SimpleListModel;

public class testCheckboxWindow extends GenericForwardComposer {

private Listbox box;

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
List list = new ArrayList();
for (int i = 0; i < 1000; i++) {
list.add("hello" + i);
}
SimpleListModel simpleListModel = new SimpleListModel(list);
box.setModel(simpleListModel);
}
}

delete flag offensive retag edit

13 Replies

Sort by » oldest newest

answered 2009-10-10 03:16:29 +0800

adam4891288 gravatar image adam4891288
657 1 5

點選checkbox的時候只能點擊checkbox的框,而不能點擊listitem的其他部份,否則會取消之前的選擇改為選中當前item。
不知道是否因為這個原因而產生你的問題。

link publish delete flag offensive edit

answered 2009-10-10 03:32:47 +0800

ring gravatar image ring
99 1

非常感谢 不过你刚才所说的并非真正地解决办法
在实际操作中,数据相当多的话,要很小心翼翼的点checkbox的框,可万一点偏了,不就之前点的全没了
不知是否有其他解决办法?

link publish delete flag offensive edit

answered 2009-10-10 03:42:46 +0800

adam4891288 gravatar image adam4891288
657 1 5

這個問題之前有朋友提出過。其實這個動作應該是符合國際規格的。比如說我們常用的網絡郵箱的相應功能等等。
如果一定要實現在listitem任何一個地方點擊都可以選中checkbox的話,可以給每一個listcell添加onClick事件監聽來實現。

link publish delete flag offensive edit

answered 2009-10-10 04:11:25 +0800

ring gravatar image ring
99 1

除了给每一个listcell添加onClick事件监听来实现外,没有别的办法了吗?

从我的代码角度来看,我是动态获取的,页面中都没有用到listcell,那又该如何实现呢?

<listbox id="box" width="250px" rows="20" fixedLayout="true"
multiple="true" checkmark="true">
<listhead>
<listheader label="Name"/>
</listhead>
</listbox>

link publish delete flag offensive edit

answered 2009-10-10 04:37:26 +0800

adam4891288 gravatar image adam4891288
657 1 5

測試學習階段當然可以如你所用的方法來構造Listbox,真正開髮時當然會使用更嚴密的方式了。
另外,要做到你想要的功能,就必須使用另外的方式構建Listbox。
PS:貌似Listitem也可以添加onClick事件來監聽的,但無論如何都要改變構造Listbox的方式。

link publish delete flag offensive edit

answered 2009-10-10 05:35:48 +0800

ring gravatar image ring
99 1

能否告诉我,你认为哪种构造Listbox是不会出现我所提出来的问题的?

link publish delete flag offensive edit

answered 2009-10-10 05:49:50 +0800

adam4891288 gravatar image adam4891288
657 1 5

其實box.setModel(simpleListModel)這種方法是調用了ZK中有個Render方法。
你可以通過在java類中繼承ListitemRenderer接口來重寫這個方法,具體寫法資料ZK的small talk裏面有相關文章介紹。剛才我找了下,一時也沒找到……我暫且把我的代碼發給你參考下吧:

public class MyClass extends GenericForwardComposer implements ListitemRenderer {
……
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		……
		ListModel listModel = new SimpleListModel(list);
		listbox.setModel(listModel);
	}

	……
	public void render(Listitem item, Object data) throws Exception {
		MyBean bean = (MyBean) data;
		new Listcell("name").setParent(item);
		new Listcell("password").setParent(item);
	}
}


不過後來我發現該方法對於列表Index的構造不是很方便,於是改用for循環手動構建Listitem然後逐個添加到Listbox上的。

link publish delete flag offensive edit

answered 2009-10-10 06:34:39 +0800

ring gravatar image ring
99 1

高手,我有好多问题都不懂呢,你能否留个QQ啊?

好交流

link publish delete flag offensive edit

answered 2009-10-10 08:20:44 +0800

adam4891288 gravatar image adam4891288
657 1 5

論壇上不方便講,給你郵件吧,郵箱給我

link publish delete flag offensive edit

answered 2009-10-10 08:24:25 +0800

tabsuny gravatar image tabsuny
102

Hi Adam,

你太小气了,~~.
发出来,有问题可以向你请教吗~~

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: 2009-10-10 02:48:03 +0800

Seen: 1,123 times

Last updated: Jun 15 '18

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