Himanshu
Himanshu

Reputation: 378

Issue in zk validation

I'm using validation with zk input constraints. When clicking the save button, doSave is still called, but it should not be.

I want to do when it's trigger, the save operation must be stop.

Another issue is, that zk allows % in Intbox.

Here is what I have tried.

validation.zul

<zk>
<window width="100%" height="100%"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('com.test.Validation')">

    <toolbar id="listToolbarProcess" sclass="vista" height="20px"
        align="start">

        <toolbarbutton label="Save" onClick="@command('doSave')" ></toolbarbutton>

    </toolbar>

    <vlayout sclass="vertical-scroll" vflex="1">

        <intbox id="priority" value="@bind(vm.value)" maxlength="3"
            constraint="no empty" ></intbox>
            <datebox value="@bind(vm.date)"></datebox>
    </vlayout>

</window>

Validation.java

 package com.test;

 import java.sql.Timestamp;

 import org.zkoss.bind.annotation.AfterCompose;
  import org.zkoss.bind.annotation.Command;
   import org.zkoss.bind.annotation.ContextParam;
   import org.zkoss.bind.annotation.ContextType;
   import org.zkoss.zk.ui.Component;

  public class Validation {

/**
 * @author Himanshu
 */
Integer value;

public Integer getValue() {
    return value;
}

public void setValue(Integer value) {
    this.value = value;
}
    Timestamp date;
public Timestamp getDate() {
return date;
    }

    public void setDate(Timestamp date) {
this.date = date;
     }

@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {

}

@Command
public void doSave() {

    System.out.println(" value =" + value);
    System.out.println(" Date Value =" + date);
}

}

Thanks Himanshu

Upvotes: 2

Views: 3617

Answers (1)

Nabil A.
Nabil A.

Reputation: 3400

Please read this part of zk doc. It explains how to avoid
the calling of databinding methods if validation fails.

If you want your input to (not) accept %, use a textbox with regex.
If you want to mask your input, look here.

Upvotes: 1

Related Questions