asked
2014-03-21 12:44:17 +0800
JMVAZ 13 ● 3 Dear all,
I'm facing a problem and I need some precious help. :)
In Zul, I had declared one form which is initialized in the Viewmodel.
Example:
<zk>
<div apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('demo.viewmodels.TestViewModel')"
form="@id('fx') @load(vm.product) @init(vm.myForm) @save(vm.product, before='submit')">
<vlayout>
<textbox value="@bind(fx.name)"/>
<textbox value="@bind(fx.description)"/>
<doublebox value="@bind(fx.price)"/>
</vlayout>
<button id="load_product" label="Select Most Recent Product" onClick="@command('select_recent')"/>
<button label="Submit" onClick="@command('submit')" />
</div>
</zk>
In the button with id "loadproduct", I want to automatically fill some inputs.
When I click in the button the command 'selectrecent' in called, but the notify change declared in the viewmodel, doesn't update the fields binded to the middle object "fx".
My viewmodel:
public class TestViewModel {
private Form myForm = new SimpleForm();
private Product product = new Product();
@Command("select_recent")
@NotifyChange("myForm")
public void selectRecent(){
myForm.setField("name", "recent_product_name");
myForm.setField("description", "recent_product_name");
myForm.setField("price", new Double(100.0));
}
@Command("submit")
public void submit(){
System.out.println( "name:" + product.getName());
System.out.println( "description:" + product.getDescription());
System.out.println( "price:"+ product.getPrice());
}
public Form getMyForm() { return myForm; }
public Product getProduct() {return product;}
public void setProduct(Product product) {this.product = product;}
}
This example posted, is a very simple example. In fact what I want to do is much more complex. I have one parent form which is filled, using the help of some modal windows. All the changes done, must be reflected in the parent form, and the save of all the inputs only can be done on the submit of the parent form.
The technical solution must use one middle object, because I will have the edition mode of the form, and all the changes done cannot be reflected in the original object, until the confirm is pressed.
Waiting one reply,
Thanks for your time.
Jaime