Revision history [back]

click to hide/show revision 1
initial version

answered 2012-06-15 08:12:41 +0800

dennis gravatar image dennis

http://www.javaworld.com....

then here if we want to handle confirm status/message, we have to create some data in MVVM model.

<hbox>
    <window title="Case 1" border="1" apply="org.zkoss.bind.BindComposer" 
        viewModel="@id('vm') @init('org.zkoss.mvvm.examples.confirm_delete.ConfirmDelete1')">
        <vbox>
            <listbox model="@bind(vm.items)"
                selectedItem="@bind(vm.selected)" width="200px">
                <template name="model" >
                    <listitem>
                        <listcell label="@load(each)" ></listcell>
                    </listitem>
                </template>
            </listbox>
        </vbox>
        <label value="@load(vm.message)" ></label>
        <hbox>
            <button label="delete" disabled="@load(empty vm.selected)" 
                onClick="@command(vm.needToConfirm?'showConfirm':'delete')" ></button>
        </hbox>
        <window title="Confirm " mode="modal" visible="@load(not empty vm.confirmMessage)" border="1" width="300px">
            <vbox hflex="1" pack="center" align="center" style="padding:10px">
                <label value="@load(vm.confirmMessage)"></label>
                <hlayout> 
                    <button label="Delete" onClick="@command('delete')" ></button>
                    <button label="Cancel" onClick="@command('cancelConfirm')" ></button>
                </hlayout>
            </vbox>
        </window>
    </window>
</hbox>





package org.zkoss.mvvm.examples.confirm_delete;

import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.NotifyChange;

public class ConfirmDelete1 extends ConfirmDeleteBase{


    String confirmMessage;

    public String getConfirmMessage(){
        return confirmMessage;
    }

    @Command @NotifyChange("confirmMessage")
    public void cancelConfirm(){
        confirmMessage = null;
    }

    @Command @NotifyChange("confirmMessage")
    public void showConfirm(){
        confirmMessage = "Do you really want to delete "+selected;
    }

    @Override
    @Command @NotifyChange({"message","items","selected","confirmMessage"})
    public void delete(){
        super.delete();
        confirmMessage = null;
        //clean confirmMessage and notify
    }

    public boolean isNeedToConfirm(){
        //simulate C doesn't need to be confirm
        if("C".equals(selected)){
            return false;
        }
        return true;
    }   
}
Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More