Databind and List problem

asked 2011-06-14 15:13:53 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6

updated 2011-06-14 15:14:24 +0800

Hi all!

I'm working on a dynamic forms rendering engine for my big project and i'm actually facing a problem with the databinding of inner lists of elements.

The bean - fake one but exactly like the ones i HAVE to import and i can't change then!

public class Rainbow {
	private Palette palette = new Palette();
	public Palette getPalette() {
		return palette;
	public void setPalette(Palette palette) {
		this.palette = palette;
	public static class Palette {
		private List<String> colors = new ArrayList<String>();
		public List<String> getColors() {
			return colors;
		public void setColors(List<String> colors) {
			this.colors = colors;

The .zul

<?page title="Binded Rainbow attempt"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
 <window id="win" width="500px" use="my.tests.RainbowWindow">
	<grid hflex="1" model="@{win.rainbow.palette.colors}" >
			<row self="@{each='color'}">
				<textbox value="@{color}" />

The stupid window

public class RainbowWindow extends Window {
	private Rainbow rainbow;	
	public void initRainbow() {
		rainbow = new Rainbow();
		rainbow.getPalette().setColors(new ArrayList<String>() {
	public Rainbow getRainbow() {
		return rainbow;

So, as you can see... databinding is failing when trying to update the values of a color.
What am i missing? :]

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2011-06-15 09:43:30 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

updated 2011-06-15 09:43:51 +0800

Search the forum for binder.loadAll();

In your controller you must first get an instance of the Binder and call the binding methods .loadAll().

link publish delete flag offensive edit

answered 2011-06-16 03:54:25 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6

updated 2011-06-16 04:01:04 +0800

Hi Terry and thanks for the suggestion!

But probably i explained badly: i have a problem only with the update not with the load... so a loadAll seems not working since the binder is already alive and kicking :]
Or... i just tried to call the .loadAll() in a bad way...

The only (tricky) way i found to solve my problem was specifying a custom converter... something like:

in the zul

<textbox value="@{color, converter=my.tests.MyConverter}" />

the custom converter

public class MyConverter implements TypeConverter {
	public Object coerceToBean(Object value, Component comp) {
		if (comp.getParent() instanceof Row) {
			Row r = (Row) comp.getParent();
			String uuid = r.getUuid();

			BindingListModelList model = (BindingListModelList) r.getGrid().getModel();
			Rows rows = (Rows) r.getParent();
			int i = 0;
			for (i = 0; i < rows.getChildren().size(); i++) {
				Row ro = (Row) rows.getChildren().get(i);
				if (ro.getUuid().equals(uuid)) {
			List obj = model.getInnerList();
			obj.add(i, value);
		return TypeConverter.IGNORE;

	public Object coerceToUi(Object value, Component comp) {
		if (comp instanceof Textbox) {
			((Textbox) comp).setValue(value + "");
		return TypeConverter.IGNORE;

which is clearly not a state-of-art general purpose piece of code!
Any news about DataBinding 2.0? =)

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




Asked: 2011-06-14 15:13:53 +0800

Seen: 359 times

Last updated: Jun 16 '11

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