On Tue, Dec 7, 2010 at 4:08 AM, Peter Karich <[email protected]> wrote:
> regarding the panels: I'm using a lot of them. But for instantiation I need
> to
> specify what to do onClick so I could reuse the panel in a different context
> somewhen later.
> I mean, when the panelA detects a click this is forwarded to the onClick
> method which is overwritten in Homepage to invoke a search.
> But if I want to reuse that panelA in a different context maybe I want to
> trigger a different onClick behaviour?

You can use this pattern of creating extension points:

class MyPanel extends Panel {
  MyPanel(id) {
    super(id);
    add(new Link<Void>("foo") {
      public void onClick() {
        onFooLinkClicked();
      }
    });
  }

  protected void onFooLinkClicked() { /* this method is designed to be
overridden */ }
}


class SomePage extends YourBasePage {
  SomePage() {
    add(new MyPanel("bar") {
      protected void onFooLinkClicked() {
        // put your page-specific logic here.
      }
    });
  }
}

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to