Listbox Renderer"

From Documentation
(Created page with "{{ZKDevelopersReferencePageHeader}} Here we describe how to implement a custom renderer for a listbox (<javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc>). For t...")
 
m ((via JWB))
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
Here we describe how to implement a custom renderer for a listbox (<javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc>). For the concepts about component, model and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].
 
Here we describe how to implement a custom renderer for a listbox (<javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc>). For the concepts about component, model and renderer, please refer to [[ZK_Developer's_Reference/MVC/Model/List_Model#Model-driven_Display|the Model-driven Display section]].
  
When a listbox (<javadoc>org.zkoss.zul.Listbox</javadoc>) is assigned with a model, a default renderer is assigned too. The default renderer will assume that each tree item has only one column, and it converts the data into a string directly<ref>If the tree is assigned a template called <tt>model</tt>, then the template will be used to render the tree. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Listbox Template|the Listbox Template section]].</ref>. If you want to display multiple columns or retrieve a particular field of the data, you have to implement <javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc> to handle the rendering.
+
When a listbox (<javadoc>org.zkoss.zul.Listbox</javadoc>) is assigned with a model, a default renderer is assigned too. The default renderer will assume that each list item has only one column, and it converts the data into a string directly<ref>If the listbox is assigned a template called <code>model</code>, then the template will be used to render the listbox. For more information, please refer to [[ZK Developer's Reference/MVC/View/Template/Listbox Template|the Listbox Template section]].</ref>. If you want to display multiple columns or retrieve a particular field of the data, you have to implement <javadoc type="interface">org.zkoss.zul.ListitemRenderer</javadoc> to handle the rendering.
  
 
For example,
 
For example,
Line 29: Line 29:
  
 
=Version History=
 
=Version History=
{{LastUpdated}}
+
 
{| border='1px' | width="100%"
+
{| class='wikitable' | width="100%"
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-

Latest revision as of 07:34, 8 July 2022

Here we describe how to implement a custom renderer for a listbox (ListitemRenderer). For the concepts about component, model and renderer, please refer to the Model-driven Display section.

When a listbox (Listbox) is assigned with a model, a default renderer is assigned too. The default renderer will assume that each list item has only one column, and it converts the data into a string directly[1]. If you want to display multiple columns or retrieve a particular field of the data, you have to implement ListitemRenderer to handle the rendering.

For example,

public class MyRenderer implements ListitemRenderer{
	public void render(Listitem listitem, Object data, int index) {
		Listcell cell = new Listcell();
		listitem.appendChild(cell);
		if (data instanceof String[]){
			cell.appendChild(new Label(((String[])data)[0].toString()));
		} else if (data instanceof String){
			cell.appendChild(new Label(data.toString()));
		} else {
			cell.appendChild(new Label("UNKNOW:"+data.toString()));
		}
	}
}

  1. If the listbox is assigned a template called model, then the template will be used to render the listbox. For more information, please refer to the Listbox Template section.

Version History

Version Date Content
6.0.0 February 2012 The index argument was introduced.



Last Update : 2022/07/08

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.