-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello!
In my application I have a grid with a dynamic number of rows and a dynamic number of columns. The cells are editable and I want to keep them in sync with my model to save the data back later.
Here is the code of my grid:
<grid vflex="1" height="100%"> <columns height="22px" menupopup="auto" sizable="true"> <column forEach="${head}" label="${(empty each) ? c:l('header.default') : each}" sort="auto" /> </columns> <rows> <row forEach="${each.value.properties}"> <label value="${each.key}" /> <textbox use="translator.ui.ComparableTextbox" apply="translator.controller.EventController" inplace="true" onChange="self.style="font-weight:bold"; tab1.label = "* " + tab1.label;" forEach="${each.value}" value="${each}" /> </row> </rows> </grid>
First, evaluated expressions (${...) are only 1-way-bindings. For 2-way binding ZK offers annotated databinding (@{xxx}).
But EL's more flexible and it's not possible to create dynamic columns with @databindig. So you have to use EL's and events.
1. Setup a composer (i.e. for the window or another headcomponent)
--> it think apply inside a forEach-loop isn't a good idea....
2. forward the event <textbox forward="onChange=onYourEvent"...
--> note: noChange created interpreted zscript --> good for prototyping, bad for productive environment
3. catch the event (ForwardEvent) inside your javacode
4. retrieve the component from the event (getTarget from the originEvent) --> textbox
4a. and follow the UI tree to get the key or object keys, i.e. getParent() --> row --> getFirstChild() --> key label
or plan B:
create the whole thin in pur java and add eventlistener like swing
/Robert
Asked: 2010-12-28 04:48:26 +0800
Seen: 381 times
Last updated: Dec 30 '10