1

bind data from zul file to modelview [closed]

asked 2013-05-29 07:05:14 +0800

demizon gravatar image demizon
179 1 6

updated 2013-05-29 07:43:47 +0800

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.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-06-07 13:49:14

Comments

SO what is the issue with this code?

sjoshi ( 2013-05-29 07:33:06 +0800 )edit

you have to mentioned what issue you are getting then i can help you

sjoshi ( 2013-05-29 07:33:47 +0800 )edit

my answer is how to get values of id, number and name (in red circles on picture)

demizon ( 2013-05-29 07:44:23 +0800 )edit

bcoz when i try System.out.println(editedKunde.getNumber(),editedKunde.getName()) I am getting null values

demizon ( 2013-05-29 07:46:47 +0800 )edit

I 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

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-05-29 08:25:12 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

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
}
link publish delete flag offensive edit
0

answered 2013-06-07 13:28:22 +0800

Matze2 gravatar image Matze2
773 7

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)

link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2013-05-29 07:05:14 +0800

Seen: 91 times

Last updated: Jun 07 '13

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