0

Native DataBinding & managed DataBinding

asked 2011-05-13 07:45:19 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

updated 2011-05-13 08:49:22 +0800

Hi,
I have a simple page

<?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>
<?taglib uri="/WEB-INF/tld/glims.list.tld" prefix="gl"?>
<?page title="Batch create" contentType="text/html;charset=UTF-8"?>
<?init class="org.glims.view.initializer.PhysicalBatchFormInitializer"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./batchgrid" ?>

<zk>
	<grid id="batchgrid"
		apply="org.glims.manager.PhysicalBatchFormManager">
		<columns sizable="true">
			<column label="${c:l('general.application.field')}"
				width="200px" />
			<column label="${c:l('general.application.value')}" />
		</columns>
		<rows>
			<row>
				<combobox id="contract_batch" constraint="no empty">
						<comboitem
							forEach="${gl:getContractBatches(1)}"
							labele="ecc.ecc."
							value="${each}" />
					</combobox>
				</hlayout>
			</row>
		        ...
			<row>
	<datebox id="delivery_date" value="@{sessionScope.newPhysicalBatch.deliveryDate}"/>
			</row>
                        ...
		</rows>
	</grid>
</zk>

where a combo is generated out of a tag lib call and there is a newPhysicalBatch object in session, binded to several fields.

In the class org.glims.manager.PhysicalBatchFormManager I try to change data on the fly from the object selected in the combobox and the one stored in session:

public void onChange$contract_batch (Event event) {
	try {
		HttpSession session = (HttpSession) Sessions.getCurrent().getNativeSession();		
		PhysicalBatch pb = (PhysicalBatch) session.getAttribute("newPhysicalBatch");
		Combobox c = (Combobox) event.getTarget().getFellow("contract_batch");
		ContractBatch cb = (ContractBatch) c.getSelectedItem().getValue();
		...
		pb.setDeliveryDate(cb.getDeliveryDate());
		...
	} catch (Exception e) {
		...
	} 
}

When I change the combobox selction, I'd then expect to see the Delivery date changed on UI (it is binded, after all), but nothing changes...
I debugged and everything is correct in session (data are updated), so I suppose there must be something I do not (still) understand in DataBinding.
Isn't enough to change the object in session (even programmatically) to see it update in UI?
Have I to (programmatically) force any action (usually otherwise performed by AnnotateDataBinderInit)?
Thanks
S

P.S. BTW, if I do not specify load-when/save-when etc. which is default behaviour for databinding?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-05-13 09:32:35 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Nice... with

<datebox id="delivery_date" value="@{sessionScope.newPhysicalBatch.deliveryDate, load-after='contract_batch.onChange'}"/>

it works fine!
BTW, is there anything that could be done instead programmatically?

link publish delete flag offensive edit

answered 2011-05-18 20:31:29 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

updated 2011-05-18 20:32:29 +0800

Hi, Steva77,

What the DataBinder do is to help moving value from bean property to UI attribute(we name it load) and/or UI attribute to bean property(we name it save). However, DataBinder must be notified to do such things. We now trigger the DataBinder to do such things by ZK events.

In your case, when you fetch the session variable and change its value, DataBinder has no way to know that you have done such things and it will do nothing. Developers have to notify DataBinder and say "Hey! I have changed something here. You should "load" value from bean to update UI". So we have such loadXxx API in DataBinder for developer to notify the DataBinder. Or developer can provide some "load-after" meta-info to tell DataBinder that "when this textbox fire onChange event, you shall "load" this datebox.

The current mechanism is somehow limit to "event" and "UI component hierarchy". In next Data Binding 2.0, we plan to introduce the concept of "load-when-variable-change/save-when-variable-change". That way, developers can "focus" on VARIABLE instead of EVENT and it makes the programming transparent to the UI hierarchy. What developers do is then simplified to tell DataBinder that "Hey! I have changed the value of this variable" and that is all. DataBinder is responsible to do the rest because you have told him (by meta-info) what should be "load/save" when the variable change.

link publish delete flag offensive edit

answered 2011-05-19 03:22:18 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

GREAT EXPLANATION!
Thank you very much!

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-05-13 07:45:19 +0800

Seen: 314 times

Last updated: May 19 '11

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