Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In the above example, the runOnLoad function is a function defined elsewhere that makes sure that the confirmModifyOnclick function is run when the document is loaded.

The standard approach in wicket is to implement this with behaviors. In this case, we need to add two behaviors to a component that requires confirmation:

No Format

  link.add(HeaderContritor.forJavaScript(MyClass.class, "confirm.js"));
  link.add(new AttributeModifier("confirmationMessage", true, new Model(message));  

Nevertheless, this approach is a bit problematic for the following reasons:

  • You need to do two things (add two behaviors) just to accomplish one task (confirmation).
  • If in the future the implementation of confirmation popups changes code might be changed in
    many places to accomplish this.

It would be better to use one behavior and to write code like this:

No Format

  link.add(new ConfirmationBehavior("message");

In this way, any implementation changes are localized in the confirmation behavior and the code is conceptually close to reality: we must do one thing in the code to accomplish one thing in the application.