Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-1017

Property of a form is not correct when validation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 6.0.1
    • 6.0.0
    • Databind 2
    • None

      1.When getting property of @bind(fx.bean.value1) in validator, it is value1 , not bean.value1

      <zk xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul/zul.xsd"
      	xmlns:n="http://www.zkoss.org/2005/zk/native">
      	<label multiline="true">
      		1.you should see value1 is A 
      		2.edit on value1, set to Aa, you will see a length validation warn
      		3.edit on value2, set to Aaaa, the message will be gone.
      		4.click update, the Info value should change to Aaaa
      	</label>
      	<window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('org.zkoss.zktest.bind.issue.B01017NestedFormPath')" 
      	validationMessages="@id('vmsgs')">
      		<hlayout>
      			Info : <label id="l12" value="@bind(vm.bean.value1)" />
      		</hlayout>
      		<div form="@id('fx') @load(vm) @save(vm, before='update')">
      			<hlayout>
      				<label value="Value1" />
      				<textbox id="t2" value="@bind(fx.bean.value1) @validator(vm.validator1)" errorMessage="@load(vmsgs[self])" />
      			</hlayout>
      		</div>
      		<button id="update" label="update" onClick="@command('update')" />
      	</window>
      </zk>
      
      package org.zkoss.zktest.bind.issue;
      
      import org.zkoss.bind.Form;
      import org.zkoss.bind.ValidationContext;
      import org.zkoss.bind.Validator;
      import org.zkoss.bind.annotation.Command;
      import org.zkoss.bind.annotation.Init;
      import org.zkoss.bind.validator.AbstractValidator;
      import org.zkoss.lang.Strings;
      
      public class B01017NestedFormPath {
      
      	Bean bean;
      	
      	@Init
      	public void init(){
      		bean = new Bean();
      		bean.value1 = "A";
      	}
      
      	public Bean getBean() {
      		return bean;
      	}
      
      	public void setBean(Bean bean) {
      		this.bean = bean;
      	}
      	
      	@Command
      	public void update() {
      		System.out.println("update "+getBean().getValue1());
      	}
      
      	public class Bean {
      		String value1;
      
      		public String getValue1() {
      			return value1;
      		}
      
      		public void setValue1(String value1) {
      			this.value1 = value1;
      		}
      
      	}
      	
      	public Validator getValidator1(){
      		return new AbstractValidator() {
      			
      			@Override
      			public void validate(ValidationContext ctx) {
      				String value = (String)ctx.getProperty().getValue();
      				Object base = ctx.getProperty().getBase();
      				String prop = ctx.getProperty().getProperty();
      				System.out.println(">>>>> base "+base+",value "+value+", prop:"+prop);
      				if(!(base instanceof Form)){
      					addInvalidMessage(ctx, "base is not a Form");
      				}else if(!"bean.value1".equals(prop)){
      					addInvalidMessage(ctx, "prop is not bean.value1");
      				}else if(Strings.isEmpty(value)){
      					addInvalidMessage(ctx, "cannot be empty");
      				}else if(value.length()<3){
      					addInvalidMessage(ctx, "length < 3");
      				}
      				
      				
      				
      			}
      		};
      	}
      }
      
      

            dennis dennis
            dennis dennis
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: