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

Converter cannot get parameters when using with form binding

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 6.0.0, Freshly
    • Fix Version/s: 6.0.0
    • Component/s: Databind 2
    • Labels:
      None

      Description

      Problem Description:

      Converter cannot get parameters by ctx.getConverterArg("key1") when using with form binding.

      Steps to Reproduce

      1. use the following code.
      2. click the button, you will see the console display the following message:
        to bean, Key1:null
        to bean, Key2:null
      <zk>
      	<vbox apply="org.zkoss.bind.BindComposer"
      		viewModel="@id('vm') @init('org.zkoss.zktest.bind.viewmodel.form.Form')"
      		width="400px">
      		<div form="@id('fx') @load(vm.order) @save(vm.order, before='compute')">
      			<textbox value="@bind(fx.name) @converter(vm.myConverter, key1=fx.name, key2='value2')" />
      			<button id="computeButton" label="Compute" onClick="@command('compute')" />
      
      		</div>
      	</vbox>
      </zk>
      
      
      
      package org.zkoss.zktest.bind.viewmodel.form;
      
      import org.zkoss.bind.BindContext;
      import org.zkoss.bind.Converter;
      import org.zkoss.bind.annotation.Command;
      import org.zkoss.zk.ui.Component;
      
      
      public class Form{
      
      	
      	public class Order{
      		private String name = "default name";
      
      		public String getName() {
      			return name;
      		}
      
      		public void setName(String name) {
      			this.name = name;
      		}
      
      	}
      	
      	
      	private Order order = new Order();
      	
      	public Order getOrder() {
      		return order;
      	}
      	
      	
      	public Converter getMyConverter(){
      		return new Converter() {
      			
      			public Object coerceToUi(Object val, Component component, BindContext ctx) {
      				String value1 = (String)ctx.getConverterArg("key1");
      				String value2 = (String)ctx.getConverterArg("key2");
      				System.out.println("to UI, myKey:"+value1);
      				System.out.println("to UI, Key2:"+value2);
      				return val;
      			}
      			
      			public Object coerceToBean(Object val, Component component, BindContext ctx) {
      				String value1 = (String)ctx.getConverterArg("key1");
      				String value2 = (String)ctx.getConverterArg("key2");
      				System.out.println("to bean, myKey:"+value1);
      				System.out.println("to bean, Key2:"+value2);
      				return val;
      			}
      		};
      	}
      	
      	// -----------command -----------------
      	@Command 
      	public void compute(){
      		
      	}
      
      
      }
      
      

        Attachments

          Activity

            People

            Assignee:
            dennis dennis
            Reporter:
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: