-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I would like to ask how can i bind data (id, number, name from component "edit data" (watch picture)) to modelview. So i can save edited data to DB.
http: //fastimages.eu/images/savewqw.png
my zul file:
<window title="Kunde" width="1025px" height="970px" border="normal" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('tutorial.SearchViewModel')">
<hbox align="center">
<checkbox checked="@bind(vm.bindCheckBox)" onCheck="@command('onCheckedAndUnchecked')" label="Show all items" />
</hbox>
<hbox align="center">
number:
<textbox value="@bind(vm.number)" />
name:
<textbox value="@bind(vm.name)" />
<button label="Add" onClick="@command('addKunde')" />
</hbox>
<listbox height="700px" model="@load(vm.kundeList)" selectedItem="@bind(vm.selectedKunde)" emptyMessage="No kunden">
<listhead>
<listheader label="ID" width="50px" />
<listheader width="300px" label="Number" />
<listheader width="300px" label="Name" />
<listheader width="150px" label="Delete" />
</listhead>
<template name="model">
<listitem>
<listcell label="@load(each.id)"/>
<listcell label="@bind(each.number)"/>
<listcell label="@bind(each.name)"/>
<listcell>
<button label="Delete" onClick="@command('removeKunde', kunde=each)" />
</listcell>
</listitem>
</template>
</listbox>
<grid>
<auxhead>
<auxheader colspan="5" class="topic">Edit Data</auxheader>
</auxhead>
<columns>
<column label="ID" align="center" />
<column label="Number" align="center" />
<column label="Name" align="center" />
<column label="Edit" align="center" />
</columns>
<rows>
<row>
<label value="@load(vm.selectedKunde.id)" width="95%" />
<textbox value="@bind(vm.selectedKunde.number)" width="95%" />
<textbox value="@bind(vm.selectedKunde.name)" width="95%" />
<button label="Save" onClick="@command('editKunde', vm.selectedKunde=each)" />
</row>
</rows>
</grid>
</window>
relevant code from modelview:
@Command
@NotifyChange("kundeList")
public void editKunde(@BindingParam("selectedKunde") Kunde editedKunde) {
kundeService.editKunde(editedKunde,editedKunde.getNumber(),editedKunde.getName());
}
To sum up: my answer is how to get values of id, number and name (in red circles on picture)
Thx for answers.
Try out this it shuold work
<button label="Save" onClick="@command('editKunde',selectedData= vm.selectedKunde)" />
And method should be like this
@Command
public void editKunde(@ContextParam(ContextType.VIEW) Component comp,
@BindingParam("selectedData") Kunde editedKunde) {
// Your business logic here
}
The following discussion was done only in the comments but led also to an answer. Since only the first comments are shown, I put the essential parts here again, so it can be found by others:
The problem I see with this code is that you directly edit the selected item, i.e. you directly change the object in your list. Consider to make a copy of it for the edit area. MVVM forms do that automatically for you. Matze2 (May 30 '13)edit
yes matze thats exactly what i am thinking about at the moment, but i have no idea how to make a copy...can you show me some simple example plz? i should change straight binding here right?: <textbox value="@bind(vm.selectedKunde.number)" width="95%"/> demizon (Jun 1 '13)
its not a good idea sjoshi (Jun 1 '13)
well, i am thinking about this because of following problem: when i choose row lets say that one on the picture (52,123,test) and after that change the value of name to f.e. "test1" and click elsewhere(lose focus of "edita data" component) it will automatically change its value on the screen... demizon (Jun 1 '13)
...without pressing "save" demizon (Jun 1 '13)
@demizon check the ZK reference documentation for MVVM form binding, e.g. http://books.zkoss.org/wiki/ZKDeveloper%27sReference/MVVM/DataBinding/FormBinding Matze2 (37 hours ago)edit
matze thx, article you provided answered and solved both my questions :) demizon (3 hours ago)
Asked: 2013-05-29 07:05:14 +0800
Seen: 91 times
Last updated: Jun 07 '13
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]
SO what is the issue with this code?
sjoshi ( 2013-05-29 07:33:06 +0800 )edityou have to mentioned what issue you are getting then i can help you
sjoshi ( 2013-05-29 07:33:47 +0800 )editmy answer is how to get values of id, number and name (in red circles on picture)
demizon ( 2013-05-29 07:44:23 +0800 )editbcoz when i try System.out.println(editedKunde.getNumber(),editedKunde.getName()) I am getting null values
demizon ( 2013-05-29 07:46:47 +0800 )editI m pretty sure i have mistake somewhere in this line: ... public void editKunde(@BindingParam("selectedKunde") Kunde editedKunde)....
demizon ( 2013-05-29 08:08:43 +0800 )edit