binding and validation doesn't work when form is in a master-detail

asked 2014-10-13 18:16:52 +0800

ZKL gravatar image ZKL
3 1

I have a grid with records(name, description, editButton), for each record I have an edit-form inside a master-detail, when I press the edit button master-details opens with populated edit-form, !!! after I change the values in form and hit Save button the new values are not saved!!!

Seems that someone override the new value with the old value. Who is "someone"?

Can anybody help me? my code is listed below, please read the comments issue is there


<grid model="@bind(vm.recordsList)">
  <column label="Name" sort="auto(name)" sortAscending="${nameAsc}" sortDescending="${nameDesc}"/>
  <column label="Description" sort="auto(description)" sortAscending="${descriptionAsc}" sortDescending="${descriptionDesc}"/>
 <template name="model">
   <detail open="@load(each.editFormVisible)">
    <div form="@id('fx') @load(vm.selectedRecord) @save(vm.selectedRecord, before='save') @validator(vm.formValidator)">
       <textbox value="@bind(fx.name)" />
       <label value="@bind(vmsgs['editFormName'])" style="color :red;" />
       <textbox value="@bind(fx.description)" />
       <label value="@bind(vmsgs['editFormDescription'])" style="color :red;" />
       <button label="Save" onClick="@command('save')"/>
<label value="${each.name}" />
<label value="${each.description}" />
<button label="Edit" onClick="@command('edit')" />


    public Validator getFormValidator(){
    return new AbstractValidator() {
    public void validate(ValidationContext ctx) {
     String name = (String) ctx.getProperties("name")[0].getValue();
//ctx.getProperties("name")[0] - sometimes here comes old value instead of new; 
//for example in this returned list: ctx.getProperties("name"), we can have 4 items 
//and the new value is on the 2nd or 3rd position(unpredictable) not on the [0]-1st as expected

     String description = (String) ctx.getProperties("description")[0].getValue();
     if(name == null || name.isEmpty()){
      addInvalidMessage(ctx, "editFormUnitMeasure", "required");
     if(description == null || description.isEmpty()){
      addInvalidMessage(ctx, "editFormDescription", "required");
     }              }


@NotifyChange({"selectedRecord", "recordsList"})
public void edit(@BindingParam("record") Record record){

@NotifyChange({"selectedRecord", "recordsList"})
public void save(){
if(selectedRecord.getName() != null && !selectedRecord.getName().isEmpty()){
   //here we need to get the new value from form, but we get the old value for name
delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted

answered 2014-10-22 11:06:12 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2014-10-22 11:43:51 +0800


Assume you have 10 data in the grid, if you click edit button on each row to open detail, you will see the selectedRecord is the changed in each detail data. Which means there are 10 middle object "fx" bind to the same selectedRecord.

Also, the validation will trigger 10 times because they are all belong to the same view model.

You should separate the view model for each form binding.

I created a zkfiddle sample here: http://zkfiddle.org/sample/34vljts/3-master-detail-form-binding

link publish delete flag offensive edit

answered 2014-10-13 19:38:16 +0800

chillworld gravatar image chillworld flag of Belgium
5337 4 9

updated 2014-10-13 19:40:01 +0800

In stead of using a validator,

Can't you just do :

<textbox value="@bind(fx.description)" constraint="no empty"/>

Everything remains the same, just the validator you can remove inclusif the labels for showing the error message.

Greetz chill.

link publish delete flag offensive edit

answered 2014-10-16 15:19:54 +0800

ZKL gravatar image ZKL
3 1

Hi chillworld,

regarding to issue: "MVVM and Validator (or Constraint)" from zkoss forum, I opted for server validator. But anyway I'm curious to find where is the problem in the case listed above by me. May be here is a bug in ZK or ZK EE works improperly without an appropriate license?

link publish delete flag offensive edit


I'm thinking that I had also problems when I used an form in a template of list or grid with multiple items. can you try to put the code outside the list for testing?

chillworld ( 2014-10-16 21:05:41 +0800 )edit

I solved my problem removing master-detail component from my application. But I'm still looking for a scientific explanation

ZKL ( 2014-10-17 14:18:30 +0800 )edit

answered 2014-10-24 07:33:22 +0800

seple gravatar image seple

thanks for that sample :)

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

1 follower



Asked: 2014-10-13 18:16:52 +0800

Seen: 49 times

Last updated: Oct 24 '14

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