Getting user confirmation commented on by Igor Vaynberg (Jan 09, 2007).

Comment:

the above use of SimpleAttributeModifier is not appropriate because it overwrites the value, a much better approach would be to insert the confirmation script as the first part of the onclick event ala

class _javascript_EventConfirmation extends AbstractBehavior {     private final String msg;     private final String event;       public _javascript_EventConfirmation(Striong event, String msg) {           this.msg=msg;            this.event=event;       }      protected void onComponentTag(ComponentTag tag) {         String script=tag.getAttributes().get(event);         script="if (!confirm('"+msg+"')) return false; "+script;         tag.put(event, onclick);     }}

now you have a reusable behavior that can be attached to links, forms, etc.

to improve make msg an IModel

Reply via email to