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

Programmatic changes to form property are not notified

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 8.0.3
    • Fix Version/s: 8.5.0
    • Component/s: Databind 2
    • Security Level: Jimmy

      Description

      If a form property is changed programatically the new value is not shown.
      In the following example the property city is changed by clicking a button but its new value is not shown.

      public class Person {
      	private String firstName;
      	private String lastName;
      	private String city;
      
      	public Person() {
      	}
      
      	public Person(String firstName, String lastName) {
      		this.firstName = firstName;
      		this.lastName = lastName;
      	}
      
      	public String getCity() {
      		return city;
      	}
      
      	public String getFirstName() {
      		return firstName;
      	}
      
      	public String getLastName() {
      		return lastName;
      	}
      
      	public void setCity(String city) {
      		this.city = city;
      	}
      
      	public void setFirstName(String firstName) {
      		this.firstName = firstName;
      	}
      
      	public void setLastName(String lastName) {
      		this.lastName = lastName;
      	}
      }
      
      public class Test {
      	private final static String[] CITIES = { "Beijing", "Delhi", "Dhaka", "Karachi", "S\u00e3o Paulo", "Shanghai" };
      
      	private static String getRandomCity() {
      		return CITIES[(int) (Math.random() * CITIES.length)];
      	}
      
      	private Person person;
      
      	@Command
      	public void doRandomCity(@BindingParam("form") Person form) {
      		if (form != null) {
      			final String old = form.getCity();
      			String city;
      			do {
      				city = getRandomCity();
      			} while (city.equals(old));
      			form.setCity(city);
      		}
      	}
      
      	@Command
      	@NotifyChange("person")
      	public void doReset() {
      	}
      
      	@Command
      	@NotifyChange("person")
      	public void doSave() {
      	}
      
      	public Person getPerson() {
      		return person;
      	}
      
      	@Init
      	public void init() {
      		person = new Person("John", "Doe");
      		person.setCity(getRandomCity());
      	}
      }
      
      <vlayout viewModel="@id('vm') @init('TestNotify')"
      	form="@id('fx') @load(vm.person) @save(vm.person, before='doSave')">
      	<hbox widths="5em,16.3em">
      		<cell align="right">
      			<label value="First Name" />
      		</cell>
      		<textbox value="@bind(fx.firstName)" hflex="1" />
      	</hbox>
      	<hbox widths="5em,16.3em">
      		<cell align="right">
      			<label value="Last Name" />
      		</cell>
      		<textbox value="@bind(fx.lastName)" hflex="1" />
      	</hbox>
      	<hbox widths="5em,16.3em">
      		<cell align="right">
      			<label value="City" />
      		</cell>
      		<textbox value="@bind(fx.city)" hflex="1" />
      	</hbox>
      	<hbox widths="7em,7em,7em">
      		<button label="Random City"
      			onClick="@command('doRandomCity',form=fx)" hflex="1" />
      		<button label="Reset" onClick="@command('doReset')"
      			disabled="@load(not fxStatus.dirty)" hflex="1" />
      		<button label="Save" onClick="@command('doSave')"
      			disabled="@load(not fxStatus.dirty)" hflex="1" />
      	</hbox>
      </vlayout>
      

        Attachments

          Activity

            People

            Assignee:
            rudyhuang rudyhuang
            Reporter:
            benedetti benedetti
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 30 minutes
                4h 30m