0

java databind

asked 2012-11-26 15:37:53 +0800

srossi gravatar image srossi
55 1

Hi all, in an MVC architecture I'm trying to add a component to the zul page in the java composer, and bind a value to that component.

Zul:

<?xml version="1.0" encoding="UTF-8"?>
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?link rel="stylesheet" type="text/css" href="/css/BDGZKStyles.css"?>
<zk xmlns="http://www.zkoss.org/2005/zul"
	xmlns:h="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
<div id="grid" apply="it.finmatica.bdg.composer.test.TestGridComposer">
<hlayout>
<label value="in zul:"/>
<textbox id="tbzul" value="@{grid$composer.s}"	width="600px" forward="onChange=grid.onChange()"/>
</hlayout>
</div>
</zk>

Composer:


	@Override
	public void doAfterCompose(Component comp) {
		super.doAfterCompose(comp)
		
		binder = new AnnotateDataBinder(comp);
		final String beanId = "beanId"
		binder.bindBean(beanId, s);
		
		tb = new Textbox();
		tb.setInplace(true);
		tb.addForward("onChange", "grid", "onChange");
		
		binder.addBinding(tb, "value", "beanId");
		grid.appendChild(tb);
		binder.loadAll()
	}
	
	public void onChange(ForwardEvent event){
		System.out.println("tb in zul: " + tbzul.getValue());
		System.out.println("tb in java: " + tb.getValue());
		System.out.println("s: " +s );
		binder.loadComponent(tb);
		binder.loadAll()
	}
}

When the page loads, tbzul and tb components get the correct value ("someString"),
if i edit value of tbzul, the string s is modified (as expected) but nothing appen to the value of tb
and if i change the value of tb, nothing happens to the value of tbzul and tb.
It seems that a binding set with addBinding() is working only when page loads. What i'm doing wrong?
many thanks Stefano

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-11-27 09:22:26 +0800

srossi gravatar image srossi
55 1

Thanks Giovanni, your example works like a charm.
I think my error was using a String directly declared in my composer (it was a test). Using a property from a real "bean" did work.

Ciao!
Stefano

link publish delete flag offensive edit

answered 2012-11-26 16:43:20 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

Ciao Stefano!
I'm not fully sure about what did you tried to achieve but... the following snippet is working:

public class TestComposer extends GenericForwardComposer {

	private AnnotateDataBinder binder;
	private Textbox tb1;
	private Textbox tb2;

	private Person person = new Person();
	
	private Component container;

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		binder = new AnnotateDataBinder(comp);

		//<textbox value="@{person.name}" hflex="1" forward="onChange=onMyChange" />
		tb2 = new Textbox();
		tb2.addForward("onChange", self, "onMyChange");
		tb2.setHflex("1");
		binder.addBinding(tb2, "value", "person.name");
		container.appendChild(tb2);
		
		binder.bindBean("person", person);
		binder.loadAll();
	}
	
	public void onMyChange(ForwardEvent event){
		System.out.println("tb1: " + tb1.getValue());
		System.out.println("tb2: " + tb2.getValue());
		System.out.println("person's name: " + person.getName() );
		binder.loadAll();
	}
}

zul file:

<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<div apply="demo.TestComposer" width="300px">
		<vlayout id="container">
			<textbox id="tb1" value="@{person.name}" hflex="1" forward="onChange=onMyChange" />
		</vlayout>
	</div>
</zk>

hope it helps!

Giovanni

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: 2012-11-26 15:37:53 +0800

Seen: 72 times

Last updated: Nov 27 '12

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