本文整理了Java中org.zkoss.zul.Listbox
类的一些代码示例,展示了Listbox
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Listbox
类的具体详情如下:
包路径:org.zkoss.zul.Listbox
类名称:Listbox
[英]A listbox.
Event:
See Specification.
Besides creating Listitem programmatically, you could assign a data model (a ListModel or GroupsModel instance) to a listbox via #setModel(ListModel) or #setModel(GroupsModel) and then the listbox will retrieve data via ListModel#getElementAt when necessary.
Besides assign a list model, you could assign a renderer (a ListitemRenderer instance) to a listbox, such that the listbox will use this renderer to render the data returned by ListModel#getElementAt. If not assigned, the default renderer, which assumes a label per list item, is used. In other words, the default renderer adds a label to a Listitem by calling toString against the object returned by ListModel#getElementAt
To retrieve what are selected in Listbox with a SelectableListModel, you shall use Selectable#getSelection to get what is currently selected object in ListModel rather than using Listbox#getSelectedItems. That is, you shall operate on the item of the ListModel rather than on the Listitem of the Listboxif you use the Selectable ListModel.
Set selection = ((Selectable)getModel()).getSelection();
[Since 6.0.0] If a model is set, whether the listbox allows the multiple selection depends on Selectable#setMultiple. In other words, the application shall not access listbox directly if a model is assigned. Rather, the application shall access the model directly.
There are two ways to handle long content: scrolling and paging. If #getMold is "default", scrolling is used if #setHeight is called and too much content to display. If #getMold is "paging", paging is used if two or more pages are required. To control the number of items to display in a page, use #setPageSize.
If paging is used, the page controller is either created automatically or assigned explicitly by #setPaginal. The paging controller specified explicitly by #setPaginal is called the external page controller. It is useful if you want to put the paging controller at different location (other than as a child component), or you want to use the same controller to control multiple listboxes.
Default #getZclass: z-listbox.(since 3.5.0)
To have a list box without stripping, you can specify a non-existent style class to #setOddRowSclass.
When used in a clustering environment, you have to make ListitemRenderer ( #setItemRenderer) and ListModel ( #setModel) either serializable or re-assign them when #sessionDidActivate is called.
[ZK EE] [Since 5.0.0]
For huge data, you can turn on Listbox's ROD to request ZK engine to load from ListModel only the required data chunk and create only the required Listitems in memory and render only the required DOM elements in browser. So it saves both the memory and the processing time in both server and browser for huge data. If you don't use the ListModel with the Listbox, turn on the ROD will still have ZK engine to render only a chunk of DOM elements in browser so it at least saves the memory and processing time in browser. Note that ROD works only if the Listbox is configured to has a limited "view port" height. That is, either the Listbox is in the "paging" mold or you have to #setHeight(String), #setVflex(String), or #setRows(int) of the Listbox to make ROD works.
You can turn on/off ROD for all Listboxes in the application or only for a specific Listbox. To turn on ROD for all Listboxes in the application, you have to specify the Library Property "org.zkoss.zul.listbox.rod" to "true" in WEB-INF/zk.xml. If you did not specify the Library Property, default is false.
org.zkoss.zul.listbox.rod
true
To turn on ROD for a specific Listbox, you have to specify the Listbox's attribute map with key "org.zkoss.zul.listbox.rod" to true. That is, for example, if in a zul file, you shall specify <custom-attributes> of the Listbox like this:
You can mix the Library Property and <custom-attributes> ways together. The <custom-attributes> way always takes higher priority. So you can turn OFF ROD in general and turn ON only some specific Listbox component. Or you can turn ON ROD in general and turn OFF only some specific Listbox component.
Since only partial Listitems are created and rendered in the Listbox if you turn the ROD on, there will be some limitations on accessing Listitems. For example, if you call
Listitem itemAt100 = (Listitem) getItemAtIndex(100);
The Listitem in index 100 is not necessary created yet if it is not in the current "view port" and you will get "null" instead.
And it is generally a bad idea to "cache" the created Listitemin your application if you turn the ROD on because Listitems might be removed later. Basically, you shall operate on the item of the ListModelrather than on the Listitem of the Listbox if you use the ListModel and ROD.
org.zkoss.zul.listbox.rightSelect Specifies whether the selection shall be toggled when user right clicks on item, if the checkmark ( #isCheckmark) is enabled.
Notice that you could specify this attribute in any of its ancestor's attributes. It will be inherited. org.zkoss.zul.listbox.rod Specifies whether to enable ROD (render-on-demand).
Notice that you could specify this attribute in any of its ancestor's attributes. It will be inherited. org.zkoss.zul.listbox.autoSort.(since 5.0.7) Specifies whether to sort the model when the following cases:
It is used only if live data ( #setModel(ListModel) and not paging ( #getPagingChild).
org.zkoss.zul.listbox.initRodSize.(since 5.0.8) Specifies the number of items rendered when the Listbox first render.
It is used only if live data ( #setModel(ListModel) and not paging ( #getPagingChild).
org.zkoss.zul.listbox.selectOnHighlight.disabled.(since 7.0.4) Sets whether to disable select functionality when highlighting text content with mouse dragging or not.
[中]列表框。
活动:
1.org。zkoss。zk。用户界面。事件当用户更改选择时,将发送SelectEvent。
1.onAfterRender在渲染模型数据时发送。(自5.0.4起)
1.当用户单击selectAll复选框时,会发送onCheckSelectAll。(自6.5.5起)
见Specification。
除了以编程方式创建Listitem外,还可以通过#setModel(ListModel)或#setModel(GroupsModel)将数据模型(ListModel或GroupsModel实例)分配给listbox,然后listbox将在必要时通过ListModel#getElementAt检索数据。
除了指定列表模型外,还可以将渲染器(ListitemRenderer实例)指定给listbox,以便listbox使用此渲染器渲染ListModel#getElementAt返回的数据。如果未指定,则使用默认渲染器,该渲染器假定每个列表项都有一个标签。换句话说,默认呈现程序通过对ListModel#getElementAt返回的对象调用toString来向Listitem添加标签
要使用SelectableListModel检索Listbox中选择的对象,应使用Selectable#getSelection获取ListModel中当前选择的对象,而不是使用Listbox#getSelectedItems。也就是说,如果使用可选择的ListModel,则应操作ListModel的项,而不是ListBox的Listitem。
Set selection = ((Selectable)getModel()).getSelection();
[自6.0.0起]如果设置了模型,列表框是否允许多选取决于可选的#setMultiple。换句话说,如果分配了模型,应用程序不应直接访问列表框。相反,应用程序应该直接访问模型。
处理长内容有两种方法:滚动和分页。如果#getMold为“default”,则在调用#setHeight且内容太多而无法显示时使用滚动。如果#getMold为“分页”,则在需要两页或更多页时使用分页。要控制页面中显示的项目数,请使用#setPageSize。
如果使用分页,则自动创建页控制器,或由#setPaginal显式分配页控制器。#setPaginal显式指定的分页控制器称为外部分页控制器。如果希望将分页控制器放置在不同的位置(而不是作为子组件),或者希望使用同一个控制器控制多个列表框,则此功能非常有用。
默认#getZclass:z-listbox。(自3.5.0起)
要使列表框不剥离,可以将不存在的样式类指定给#setOddRowSclass。
####集群和序列化
在集群环境中使用时,必须使ListitemRenderer(#setItemRenderer)和ListModel(#setModel)可序列化,或者在调用#SessionDiActivate时重新分配它们。
####按需渲染(rod)
[ZK EE][5.0.0以来]
对于大数据,您可以打开Listbox的ROD,请求ZK引擎仅从ListModel加载所需的数据块,并在内存中仅创建所需的Listitems,在浏览器中仅呈现所需的DOM元素。因此,它在服务器和浏览器中为海量数据节省了内存和处理时间。如果不将ListModel与Listbox一起使用,则启用ROD仍将使ZK引擎在浏览器中仅渲染一块DOM元素,这样至少可以节省浏览器中的内存和处理时间。请注意,只有当列表框配置为具有有限的“查看端口”高度时,ROD才会工作。也就是说,要么列表框处于“分页”模式,要么您必须设置列表框的#setHeight(String)、#setVflex(String)或#setRows(int)才能使ROD工作。
可以为应用程序中的所有列表框打开/关闭ROD,也可以仅为特定列表框打开/关闭ROD。要为应用程序中的所有列表框启用ROD,必须在WEB-INF/zk中将库属性“org.zkoss.zul.listbox.ROD”指定为“true”。xml。如果未指定库属性,则默认值为false。
org.zkoss.zul.listbox.rod
true
要为特定的Listbox启用ROD,您必须使用键“org.zkoss.zul.Listbox.ROD”将Listbox的属性映射指定为true。也就是说,例如,如果在zul文件中,您应该像这样指定列表框的<custom attributes>:
您可以将库属性和<custom attributes>方式混合在一起。<custom attributes>方式始终具有更高的优先级。所以,您可以在一般情况下关闭ROD,而只打开某些特定的Listbox组件。或者,您可以在一般情况下打开ROD并仅关闭某些特定的Listbox组件。
由于如果打开ROD,则只会在Listbox中创建和呈现部分Listitems,因此访问Listitems会受到一些限制。例如,如果你打电话
Listitem itemAt100 = (Listitem) getItemAtIndex(100);
如果索引100中的Listitem不在当前“查看端口”中,则不需要创建它,您将得到“null”。
如果打开ROD,则在应用程序中“缓存”创建的ListItem通常是一个坏主意,因为Listitems可能稍后会被删除。基本上,如果使用ListModel和ROD,您应该操作ListModel的项,而不是Listbox的Listitem。
####自定义属性
组织。zkoss。祖尔。列表框。rightSelect指定如果选中标记(#isCheckmark)已启用,则当用户右键单击项目时,是否应切换选择。
请注意,您可以在其祖先的任何属性中指定此属性。它将被继承。组织。zkoss。祖尔。列表框。rod指定是否启用rod(按需渲染)。
请注意,您可以在其祖先的任何属性中指定此属性。它将被继承。组织。zkoss。祖尔。列表框。自动排序。(自5.0.7起)指定在以下情况下是否对模型进行排序:
1.调用#setModel并设置Listheader#setSortDirection。
1.调用Listheader#setSortDirection。
1.模型接收ListDataEvent并设置Listheader#setSortDirection。
如果要在接收ListDataEvent时忽略排序,可以将值指定为“ignore.change”。
请注意,您可以在其祖先的任何属性中指定此属性。它将被继承。组织。zkoss。祖尔。列表框。groupSelect指定此列表框下的列表组是否可选择。请注意,您可以在其祖先的任何属性中指定此属性。它将被继承。默认值为false。组织。zkoss。祖尔。列表框。预装尺寸。(自5.0.8起)指定从客户端接收渲染请求时要预加载的项目数。
仅当实时数据(#setModel(ListModel)而非分页(#getPagingChild)时才使用它。
组织。zkoss。祖尔。列表框。initRodSize。(自5.0.8起)指定列表框首次渲染时渲染的项目数。
仅当实时数据(#setModel(ListModel)而非分页(#getPagingChild)时才使用它。
组织。zkoss。祖尔。列表框。选择On Highlight。残废(自7.0.4起)设置是否在通过鼠标拖动突出显示文本内容时禁用选择功能。
代码示例来源:origin: org.carewebframework/org.carewebframework.cal.ui.patientselection.v1
private void displaySearchMessage(String message) {
lstSearch.clearSelection();
lstSearch.setModel((ListModelList<?>) null);
lstSearch.getItems().clear();
if (message != null) {
lstSearch.appendItem(message, null).setTooltiptext(message);
}
Clients.scrollIntoView(lstSearch.getFirstChild());
}
代码示例来源:origin: org.carewebframework/org.carewebframework.vista.security.impl
/**
* Returns the selected institution, if any.
*
* @return An institution object. May be null.
*/
private Organization getSelectedOrganization() {
Listitem item = j_domain.getSelectedItem();
return item == null ? null : (Organization) item.getValue();
}
代码示例来源:origin: org.carewebframework/org.carewebframework.vista.ui.context.encounter
public void onCreate() {
ZKUtil.wireController(this, this);
lstAllProviders.setItemRenderer(providerRenderer);
lstAllProviders.setModel(modelProviders);
lstEncounterProviders.setItemRenderer(providerRenderer);
}
代码示例来源:origin: stackoverflow.com
@Listen("onDrop = #userListbox")
public void onDragDropUserListitem(DropEvent dropEvent){
Listbox droppedListbox = (Listbox)dropEvent.getTarget());
Listitem draggedListitem = (Listitem)dropEvent.getDragged();
if (draggedListitem instanceof Listitem) {
droppedListbox.insertBefore(draggedListitem, droppedListbox.getNextSibling());
}else{
droppedListbox.appendChild(draggedListitem);
}
}
代码示例来源:origin: org.zkoss.zk/zul
/**
* Removes the child item in the list box at the given index.
*
* <p>
* Note: if live data is used ({@link #getModel} is not null), the returned
* item might NOT be loaded yet. To ensure it is loaded, you have to invoke
* {@link #renderItem}.
*
* @return the removed item.
*/
public Listitem removeItemAt(int index) {
final Listitem item = getItemAtIndex(index);
removeChild(item);
return item;
}
代码示例来源:origin: org.zkoss.zk/zul
/* package */Listgroup getListgroupAt(int index) {
if (_groupsInfo.isEmpty())
return null;
final int[] g = getGroupsInfoAt(index);
if (g != null) {
return (Listgroup) getItemAtIndex(g[0]);
}
return null;
}
代码示例来源:origin: org.zkoss.zk/zul
if (listbox.getModel() == null) {
final List<Listitem> items = listbox.getItems();
if (listbox.hasGroup()) {
for (Listgroup group : new ArrayList<Listgroup>(listbox.getGroups()))
sortCollection(children, cmprx);
for (Component c : children)
listbox.appendChild(c);
} finally {
Scopes.afterInterpret();
listbox.invalidate();
代码示例来源:origin: org.zkoss.zk/zkplus
public List getItems(Component comp) {
if (comp instanceof Listbox) {
final Listbox listbox = (Listbox) comp;
return listbox.getItems();
} else {
throw new UiException("Unsupported type for ListitemCollectionItem: " + comp);
}
}
代码示例来源:origin: org.zkoss.zk/zul
@SuppressWarnings("rawtypes")
private void doInitRenderer() {
if (getPage() == null)
return;
setMultiple(((Selectable) _model).isMultiple());
if (inPagingMold()) {
pgsz = _pgi.getPageSize();
ofs = _pgi.getActivePage() * pgsz;
} else {
pgsz = inSelectMold() ? getItemCount() : getDataLoader().getLimit();
ofs = inSelectMold() ? 0 : getDataLoader().getOffset();
final int cnt = getItemCount() + getDataLoader().getOffset();
if (ofs >= cnt) { // not possible; just in case
ofs = cnt - pgsz;
int realOfs = ofs - getDataLoader().getOffset();
if (realOfs < 0)
realOfs = 0;
boolean open = true;
for (Listitem item = getItems().size() <= realOfs ? null : getItems().get(realOfs), nxt; j < pgsz
&& item != null; item = nxt, j++) {
nxt = nextListitem(item); //retrieve first since it might be changed
getDataLoader().updateModelInfo();
} catch (Throwable ex) {
renderer.doCatch(ex);
代码示例来源:origin: org.carewebframework/org.carewebframework.rpms.ui.core
private void loadResults(List<String> v) {
lbResults.getItems().clear();
lbResults.appendChild(item);
String pcs[] = s.split("\\^");
StringBuilder sb = new StringBuilder();
((Listheader) lbResults.getListhead().getChildren().get(sortCol)).sort(true, true);
代码示例来源:origin: org.carewebframework/org.carewebframework.rpms.ui.core
@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
String[] subsets = (String[]) arg.get("subsets");
TermSubset termSubsets = TermUtil.getSubset(null);
for (String subset : subsets) {
Listitem item = new Listitem(termSubsets.getMemberName(subset));
item.setValue(subset);
lbSubset.appendChild(item);
}
if (subsets.length == 1) {
pnlSubset.setVisible(false);
lbSubset.setSelectedIndex(0);
((Window) root).getCaption().setLabel(lbSubset.getSelectedItem().getLabel());
}
treeSearch.setItemRenderer(termMatchRenderer);
}
代码示例来源:origin: org.carewebframework/org.carewebframework.rpms.ui.problem
private void restoreGridState() {
lbProblems.clearSelection();
for (Object object : lbProblems.getItems()) {
Listitem item = (Listitem) object;
lbProblems.renderItem(item);
if (selectedProblems.contains(item.getValue())) {
item.setSelected(true);
}
}
selectedProblems.clear();
updateControls();
}
代码示例来源:origin: org.zkoss.zk/zul
avail.addAll(_listbox.getHeads());
final Listfoot listfoot = _listbox.getListfoot();
if (listfoot != null)
avail.add(listfoot);
final Paging paging = _listbox.getPagingChild();
if (paging != null)
avail.add(paging);
final Frozen frozen = _listbox.getFrozen();
if (frozen != null)
avail.add(frozen);
if (_listbox.getItemCount() > 0) {
Component item = _listbox.getItems().get(0);
while (item != null) {
if (pgsz == 0)
代码示例来源:origin: org.carewebframework/org.carewebframework.rpms.ui.skintest
/**
* @see org.carewebframework.ui.FrameworkController#doAfterCompose(org.zkoss.zk.ui.Component)
*/
@Override
public void doAfterCompose(final Component comp) throws Exception {
super.doAfterCompose(comp);
bgoSecurity = BgoUtil.initSecurity("BGO DISABLE SK EDITING", null);
lbTests.setItemRenderer(skinTestRenderer);
RowComparator.autowireColumnComparators(lbTests.getListhead().getChildren());
getAppFramework().registerObject(patientContextEventHandler);
getAppFramework().registerObject(encounterContextEventHandler);
patientContextEventHandler.committed();
log.trace("Controller composed");
}
代码示例来源:origin: org.carewebframework/org.carewebframework.cal.ui.patientselection.v1
/**
* Search for matching patients based on user input.
*/
private void doSearch() {
log.trace("Start doSearch()");
Clients.clearBusy();
displaySearchMessage(null);
try {
lstSearch.clearSelection();
List<Patient> matches = PatientSearchUtil.execute(edtSearch.getValue(), 100);
if (matches != null) {
lstSearch.setModel(new ListModelList<Patient>(matches));
if (matches.size() == 1) {
lstSearch.setSelectedIndex(0);
}
}
} catch (Exception e) {
displaySearchMessage(e.getMessage());
}
edtSearch.setFocus(true);
edtSearch.select();
Events.postEvent(Events.ON_SELECT, lstSearch, null);
}
代码示例来源:origin: org.carewebframework/org.carewebframework.vista.ui.cwad
public void onClick$lstAllergies() {
Listitem item = lstAllergies.getSelectedItem();
if (item != null) {
lstAllergies.clearSelection();
String s = item.getValue();
List<String> lst = broker.callRPCList("RGCWARCV DETAIL", null, patientId, StrUtil.piece(s, U));
ReportBox.modal(lst, code2Text('A'), allowPrint);
}
}
代码示例来源:origin: org.carewebframework/org.carewebframework.vista.ui.encounter
protected boolean populateListbox(Listbox lb, List<?> data) {
lb.setModel((ListModel<?>) null);
lb.setModel(new ListModelList<Object>(data));
return data.size() > 0;
}
代码示例来源:origin: org.carewebframework/org.carewebframework.cal.ui.reporting
/**
* Initializes the controller. Loads user preferences and properties.
*/
@Override
protected void initializeController() {
setMeshElement(listBox, "list");
super.initializeController();
listBox.setItemRenderer(itemRenderer);
setMultiple(listBox.isMultiple());
if (listBox.getListhead() != null) {
RowComparator.autowireColumnComparators(listBox.getListhead().getChildren());
}
}
代码示例来源:origin: org.carewebframework/org.carewebframework.vista.security.impl
final Listitem li = new Listitem();
li.setValue(organization);
j_domain.appendChild(li);
IdentifierDt abbr = FhirUtil.getIdentifier(organization.getIdentifier(), "ABBREVIATION");
li.appendChild(new Listcell(abbr == null ? organization.getName().getValue() : abbr.getValue().getValue()));
if (j_domain.getChildren().size() > 0) {
if (j_domain.getSelectedIndex() == -1) {
j_domain.setSelectedIndex(0);
代码示例来源:origin: org.carewebframework/org.carewebframework.cal.ui.reporting
/**
* Sets the list item renderer.
*
* @param itemRenderer The item renderer.
*/
public void setItemRenderer(ListitemRenderer<M> itemRenderer) {
this.itemRenderer = itemRenderer;
if (listBox != null) {
listBox.setItemRenderer(itemRenderer);
}
}
内容来源于网络,如有侵权,请联系作者删除!