0

Multiple row save in form MVVM

asked 2016-07-06 03:53:28 +0800

HiteshR gravatar image HiteshR
1 2

I have to submit multiple rows at a time.

I have USER POJO and Address POJO from JAVA.

public class User{ private String name; //other property private List

address; //getter setter }

public class Address{ public String city; public String state; }

Now from UI side I have to dynamically add multiple address by click on addnew button from UI so new address row will be display on UI.

when I click on save all data will be pass as form.

I am not able to set address as list in form for User POJO.

delete flag offensive retag edit

Comments

Hi Darksu

Thank you very much for help.

I followed below example for test

http://blog.zkoss.org/2015/02/03/zk8-new-form-binding-approach/ https://github.com/zkoss-demo/zk8-formbinding-demo

But for Category list I set constraint for Category but it is not working.

Thanks, Hitesh

HiteshR ( 2016-07-06 11:57:20 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-07-06 05:37:34 +0800

Darksu gravatar image Darksu
1991 1 4

Hello HiteshR,

At the following url, you can find information on Data Binding - Collection and selection.

http://books.zkoss.org/zk-mvvm-book/8.0/databinding/collectionand_selection.html

Thus can bind directly with the Address class, and save together the data.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2016-07-18 18:40:12 +0800

HiteshR gravatar image HiteshR
1 2

updated 2016-07-18 18:40:56 +0800

Hi Darksu Thank you very much for help. Below is my code for adding multiple row but constraint is not working at severity. Can you please help if you know what is problem?

1) Problem POJO

public class Problem{

private String name;
private String desc;
private String isAvailable;
//other property

private List<Deficiency> deficiencies = new ArrayList<Deficiency>();

//getter setter

}

2) Deficiency POJO

public class Deficiency{

private String severity;
//other property
//gettr setter

}

3) method to dynamically add Deficiency

@Command public void addDefeciency(@BindingParam("problem") Problem problem) {

Deficiency deficiency = new Deficiency();
List<Deficiency> deficiencies = problem.getDeficiencies();
deficiencies.add(deficiency);

}

4) to display on UI

<groupbox form="@id('fx') @load(vm.currentProblem) @save(vm.currentProblem, before={'save'})" hflex="true" mold="3d"> <label style="font-weight:bold; color:#215891;" value="Test: "/> <groupbox> <grid hflex="true"> <columns> <column width="140px"/> <column/> <column width="120px"/> <column/> </columns> <rows>

                <row>
                    <label value="Available?" />
                    <hlayout>
                        <combobox
                            constraint="no empty:please select" readonly="true"
                            selectedItem="@bind(fx.isAvailable)">
                            <comboitem label="Y"
                                value="1" />
                            <comboitem label="N"
                                value="0" />
                        </combobox>
                    </hlayout>
                </row>
            </rows>
        </grid>
    </groupbox>

    <groupbox>
        <caption label="Defeciency" />
        <grid model="@bind(fx.deficiencies)">
            <columns>
                <column width="100%" />
                <column />
            </columns>
            <template name="model">
                <row>
                    <grid>
                        <columns>
                            <column width="140px" />
                            <column />
                            <column width="120px" />
                            <column />
                        </columns>
                        <rows>
                            <row hflex="3">
                                <label value="Severity" />
                                    <combobox
                                        constraint="no empty:please select"
                                        readonly="true"
                                        selectedItem="@bind(each.severity)">
                                        <comboitem label="Y"
                                            value="1" />
                                        <comboitem label="N"
                                            value="0" />
                                    </combobox>                         
                            </row>
                        </rows>
                    </grid>
                </row>
            </template>
        </grid>
        <button onClick="@command('addDefeciency',problem=fx)" label="Add Defeciency"/>

    </groupbox>

    <groupbox>
        <button label="Save"
            onClick="@command('save')">
        </button>
    </groupbox>

</groupbox>

Thanks, Hitesh

link publish delete flag offensive edit

Comments

are you working for amanda project?

hswain ( 2016-07-25 07:58:22 +0800 )edit
Your answer
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
1 follower

RSS

Stats

Asked: 2016-07-06 03:53:28 +0800

Seen: 54 times

Last updated: Jul 18 '16

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