0

Listbox and Groupsmodel

asked 2011-08-10 12:50:11 +0800

twiegand gravatar image twiegand
1807 3

updated 2011-08-10 12:54:13 +0800

Hi everyone,

We are trying to implement a <listbox> using the groupsmodel and seem to be running into significant hurdles with databinding and getting it to render content properly (running ZK 5.0.7.1).

Please consider the following Java snippet:

class Datem {
	String string1;
	String string2;
	
	public Datem(String val1, String val2){
		string1 = val1;
		string2 = val2;
	}				
	
	public String getString1(){
		return string1;
	}
	
	public void setString1(String val){
		string1 = val;
	}
	
	public String getString2(){
		return string2;
	}
	
	public void setString2(String val){
		string2 = val;
	}
	
	public String toString(){
		return string1 + " : " + string2;
	}
}

Object[][] data = {
	{new Datem("Cell 1-0", "First")}, 									//Group 1
	{new Datem("Cell 2-0", "Second"), new Datem("Cell 2-1", "Third")}, 					//Group 2
	{new Datem("Cell 3-0", "Fourth"), new Datem("Cell 3-1", "Fifth"), new Datem("Cell 3-2", "Sixth")} 	//Group 3
};

Object[] heads = {"Group 1", "Group 2", "Group 3"};

GroupsModel groupsmodel = new SimpleGroupsModel(data, heads);

All of the examples I can find for using a <listbox> with a groupsmodel have very minimal decoration on the <listbox> component itself.  Here is some example zul:

<listbox  model="@{groupsmodel}" selectedItem="@{selected}"/>
<separator/>
<hlayout>
	<textbox value="@{selected.string1}"/>
	<separator/>
	<textbox value="@{selected.string2}"/>
</hlayout>

This seems to render but databinding does not seem to work as a normal <listbox> would.  For example, if you select a row and then update the value in one of the textboxes below, the value does not get refreshed in the listbox above.  However, it does seem to be saving the backing information because if you select a different row and then come back to the original one, the changed value does indeed show up in the textbox ( just not in the listbox).
 

Because of the need to put values in columns, assign custom attributes, capture events, etc. we need to do more than what the above zul provides.  However, if we try to add "body" to the listbox, the Null Pointer Errors (NPE) come fast and furious.  For example, here is the same zul with more detail:

<listbox  model="@{groupsmodel}" selectedItem="@{selected}">
	<listhead>
		<listheader label="Name"/>
		<listheader label="Place"/>
	</listhead>

	<listgroup />  <!-- Should this be used here?  If so, what should it be pointed to? -->

	<listitem self="@{each=item}" value="@{item}">
		<listcell label="@{item.string1}"  />
		<listcell label="@{item.string2}"  />
	</listitem>
</listbox>
<separator/>
<hlayout>
	<textbox value="@{selected.string1}"/>
	<separator/>
	<textbox value="@{selected.string2}"/>
</hlayout>

As you'll notice in the zul code above, there is a <listgroup> component.  The inclusion/exclusion of this component does not seem to affect the results.  Maybe there is something that the <listgroup> needs to be pointed to like <listitem>?

Also of note is that once you click through the NPE dialogue boxes and then click on a row, the values populate correctly.  Unfortunately, if you try to open/close a group, the NPE errors start firing again.

We would like to stay away from using a listitemrender if at all possible.  Getting databinding to work with that seems rather messy and I've got team members with varying levels of skill.

Can anyone point me in the right direction please?  Perhaps there is some documentation I have missed in my searches.

I sure appreciate any help.  My apologies for the lengthy post.

Kind regards,

Todd

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2011-08-17 10:26:45 +0800

twiegand gravatar image twiegand
1807 3

Push.

Does anyone know how to make this work?

link publish delete flag offensive edit

answered 2011-08-17 12:05:24 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-08-17 12:05:54 +0800

Hi Todd,

interesting. I have never used the GroupsModel. But i will play a little bit with it.

First thing i have realize is that without an explizite declaration of a bean property to a listcell it seems to take the toString method.

public String toString() {
	return string1 + " : " + string2 +"333333333";
	}

i will look further.

best
Stephan

link publish delete flag offensive edit

answered 2011-08-17 12:22:01 +0800

twiegand gravatar image twiegand
1807 3

Thank you very much indeed, Stephan!

Todd

link publish delete flag offensive edit

answered 2011-08-17 13:03:49 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2011-08-17 14:04:25 +0800

Seems that the Groupsmodel is never updated since 3.5.0. Next it handles groups of 'data pairs'. In my first understanding of the the word GroupModel i imagine a grouping model. Is the GroupsModelArray you search?
I have same NPE in all of my cases.

- ListItem/Listcells should not declared if using GroupsModel.
- Listgroup (Don't know what it's do if declared in zul.)
- GroupsModel handles the model self in one way with the toString method.

best
Stephan

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: 2011-08-10 12:50:11 +0800

Seen: 409 times

Last updated: Aug 17 '11

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