Messagebox.show("Are you sure to save?", "Confirm Dialog", Messagebox.OK | Messagebox.IGNORE | Messagebox.CANCEL, Messagebox.QUESTION, new org.zkoss.zk.ui.event.EventListener() { public void onEvent(Event evt) throws InterruptedException { if (evt.getName().equals("onOK")) { alert("Data Saved !"); } else if (evt.getName().equals("onIgnore")) { Messagebox.show("Ignore Save", "Warning", Messagebox.OK, Messagebox.EXCLAMATION); } else { alert("Save Canceled !"); } } });i don't like put code everywhere process data like that. in ZK Forums i see example good idea to minimalizir boiler plate like that. check this link But, I Have a simple idea to extends component button put message box there. check this out.
package id.co.sm; import org.zkoss.zk.ui.IdSpace; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.ext.AfterCompose; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zul.Button; import org.zkoss.zul.Messagebox; @VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class) public class ExtBtnConfirm extends Button implements IdSpace,AfterCompose{ private static final long serialVersionUID = 1272856633449159555L; public static final String ON_SAVE_STR="onProcess"; String messageConfirm; public ExtBtnConfirm() { super(); } @Override public void afterCompose() { addEvent(); } public void addEvent(){ addEventListener(Events.ON_CLICK, new EventListenerthis is my Zul() { public void onEvent(Event arg0) throws Exception { Messagebox.show(messageConfirm, "Confirmation", Messagebox.YES|Messagebox.NO, Messagebox.QUESTION, new EventListener () { public void onEvent(Event e) throws Exception { if(e.getName().equals(Messagebox.ON_YES)) Events.postEvent(new EventOnProcess()); } }); } }); } public class EventOnProcess extends Event{ private static final long serialVersionUID = 1L; public EventOnProcess() { super(ON_SAVE_STR, ExtBtnConfirm.this); // TODO Auto-generated constructor stub } } public String getMessageConfirm() { return messageConfirm; } public void setMessageConfirm(String messageConfirm) { this.messageConfirm = messageConfirm; } }
index.zul
View Model
package id.co.sm; import org.zkoss.bind.annotation.Command; import org.zkoss.zul.Messagebox; public class VM_TestButton { @Command public void doProcess() { Messagebox.show("Test Confirm Button Processing.....!"); } }and The final result
that's it. :D my English level elementary. sorry! if you want to read my code all. check this link.. I hope you understand when you reading my code. hahahaha...
see yaa
No comments:
Post a Comment