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

ValidationContext support a new flag that can identify the value of single field whether is valid when use form binding

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 6.5.2
    • Fix Version/s: 6.5.3
    • Component/s: Databind 2
    • Security Level: Jimmy
    • Labels:
      None

      Description

      http://screencast.com/t/oPc4LVgBTsc4

      public class MyVM {
      
      	private Data data = new Data();
      	
      	public Data getData() {
      		return data;
      	}
      	
      	public void setData(Data data) {
      		this.data = data;
      	}
      	
      	public Validator getValidator() {
      		return new AbstractValidator () {
      
      			public void validate(ValidationContext ctx) {
      				String val = (String)ctx.getProperty().getValue();
      				if (val == null || val.trim().length() == 0) {
      					addInvalidMessage(ctx, "please type text");
      				}
      				
      				 Component comp = ctx.getBindContext().getComponent();
      		         if (comp != null) {
      		        	 
      		        	 System.out.println(comp + ": " + ctx.isValid());
      		        	 
      		             ((HtmlBasedComponent)comp).setSclass(
      		                     ctx.isValid() ?  "": "red");
      		         }
      					
      			}
      			
      		};
      	}
      	
      	@Command
      	public void save() {
      	}
      	
      	public static class Data {
      		private String value1 = "val1";
      		private String value2 = "val2";
      		
      		public String getValue1() {
      			return value1;
      		}
      
      		public void setValue1(String value) {
      			this.value1 = value;
      		}
      		
      		public String getValue2() {
      			return value2;
      		}
      
      		public void setValue2(String value) {
      			this.value2 = value;
      		}
      		
      	}
      }
      
      
      <zk>
      	<style>
      		.red,
      		.red .label-textbox-input {
      			border: 1px solid red;
      		}
      		
      		.label-textbox-macro {
      			border: none;
      		}
      	</style>
      	
      	
      	<window apply="org.zkoss.bind.BindComposer"
      		viewModel="@id('vm') @init('foo.MyVM')"
      		validationMessages = "@id('vmsgs')">
      		
      		<div form="@id('fx')
      			@load(vm.data)
      			@save(vm.data, before='save')">
      		
      			<vlayout>
      				<textbox id="val1Tb"
      					value="@bind(fx.value1)@validator(vm.validator)" />
      
      				<textbox id="val2Tb"
      					value="@bind(fx.value2)@validator(vm.validator)"/>
      				
      				<label value="@load(vmsgs[val1Tb])" />
      				<label value="@load(vmsgs[val2Tb])" />
      				
      				<button label="save" onClick="@command('save')"/>
      			</vlayout>
      		
      		</div>
      	</window>
      	
      </zk>
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            jimmyshiau jimmyshiau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: