Prevent Save Data in Invalid Form

asked 2015-08-18 07:10:42 +0800

fanjavaid gravatar image fanjavaid

Hello, I try to create simple User Registration using Zkoss, and implement MVVM Concept on it. When i try to emptying some fields, Zkoss validate it but the Submit value still passed to ViewModel. And i get null value.

How to prevent submitted value pass to ViewModel when found invalid data?

Here is my index.zul

    <window border="normal" width="400px" title="Create New Account"
        viewModel="@id('vm') @init('com.fanjavaid.mvvm.viewmodel.UserViewModel')">

        <grid hflex="1">
            <columns visible="false">
                <column />
                <column />

                <auxheader colspan="2" label="Registration Form (MVVM)" style="font-size:16px" image="/images/vcard_add.png" />

                    User Name <textbox id="username" hflex="1" constraint="No Empty" value="@bind(vm.username)" />
                    <radiogroup id="genderRadio" selectedItem="@bind(vm.gender) @load(vm.gender)">
                        <radio label="Male" value="male" image="/images/user.png" />
                        <radio label="Female" value="female" image="/images/user_female.png" />
                    Birthday <datebox id="birthdayBox" hflex="1" value="@bind(vm.birthday)" constraint="no empty, no today, no future"/>
                <row spans="2" align="center">
                        <checkbox id="acceptTermCheckbox" checked="@bind(vm.agree)" /> Accept Term of Use
                <row spans="2" align="right">
                        <button id="resetButton" label="Reset" />
                        <button id="submitButton" label="Submit" disabled="@load(empty vm.username) @load(empty vm.birthday) @load(!vm.agree) @save(!vm.agree)" onClick="@command('save')" />

And here is my ViewModel :

public class UserViewModel {
    private String username;

    private String gender;

    private Date birthday;

    private List<User> userList = new ArrayList<User>();

    private boolean agree;

    public UserViewModel() {
        this.gender = "male";

    public void save() {
        userList.add(new User(username, gender, birthday));

        System.out.println("Updated User List : ");
        for (User user : userList) {

Thank you...

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-08-19 07:22:42 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

Just use the middle object provided by ZK.

You can read it in this link :


Greetz chill.

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




Asked: 2015-08-18 07:10:42 +0800

Seen: 29 times

Last updated: Aug 19 '15

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