0

Programming (Listbox) in Java

asked 2008-11-26 21:10:32 +0800

lamh gravatar image lamh
84 3

I am new to ZK. I'd like to explore the idea of using Zk to build UI completely in java, taking advantage of type checking and IDE features. Does anyone do this?

I have some success in creating simple button, label etc. I try to create a table (Listbox). It seems trivial in zul, but I can't get it properly composed in java. In particular, the table has 3 column headers. Only the first column header is shown. The other column headers are missing.

                Listbox listbox = new Listbox();
		SimpleListModel listModel = new SimpleListModel(data);
		listbox.setModel(listModel);
		
		listhead = new Listhead();
		listhead.setParent(listbox);
		
		Listheader listheader = new Listheader("ID");
		listheader.setParent(listhead);
		listhead.appendChild(listheader);
		
		listheader = new Listheader("First Name");
		listheader.setParent(listhead);
		listhead.appendChild(listheader);
		
		listheader = new Listheader("Last Name");
		listheader.setParent(listhead);
		listhead.appendChild(listheader);
		
		listbox.appendChild(listhead);
		
		this.appendChild(listbox);

Can someone shed some light on this?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-11-27 00:43:54 +0800

robertpic71 gravatar image robertpic71
1275 1

You are mixing 2 different ways to get a java-built listbox.

Variant 1.) Using a model and an listitemrender.

Variant 2.) Fill the listbox with javacode - appendChild(Listitem) where Listitem contents the Listcell's

When you remove the model, your listheader should be ok. But you have to fill the listbox with
GUI-Elements (Listitem/Listcell).

With model you need to code a ListitemRenderer.html.
No big thing.

 void 	render(Listitem item, java.lang.Object data)
//           Renders the data to the specified list item.
YourBean yourBean = (YourBean) data;
item.appendChild(new Listcell(data.getFirstName());
item.appendChild(new Listcell(data.getLastName());
...


>> ... completely in java, taking advantage of type checking and IDE features. Does anyone do this?
I know that some people here use java-only.
But (in my opinion) there are a lot of things, that makes the (programmers) life easier with zul:
+ databinding (@,$) including an automatic ListItemrender
+ structured GUI-Code ( indentation, nesting)
+ WYSIWYG with ZK Studio
+ autowired components and events
+ less lines (each set of an attribute is one line in javacode)
+ hot deployment for zul-files (no serverrestart for gui-changes/zscript)
+ VariableResolver (can set directly i.e. the attribute model)
i.e. fill a combobox directly from a spring resource

<combobox id="fromcountry"> 
<comboitem label="${each.description}" value="${each}" forEach="${countryManager}" /> 
</combobox> 

However, some arguments for java only:
+ better refactoring (checks also the gui-layer)
+ better type checking
++ type checking for new methods/attributes from extended GUI-Components
+ better for very dynamic views
+ easier swing/swt migration

/Robert

link publish delete flag offensive edit

answered 2008-11-27 00:52:00 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hello,

You have to implement multiple column renderer, and you can refer to this smalltalk.

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: 2008-11-26 21:10:32 +0800

Seen: 731 times

Last updated: Nov 27 '08

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