Hi all,

sorry, maybe I didn't explain my problem very well. I am trying it again.

I am using exactly this "stub-method" approach for all my panels.

But in HomePage I am wiring all those panels together to use them.
I appended** an example, where the onTagClick method is overriden in HomePage.init
to use the doSearch method and lastQuery variable of HomePage.

The only possible solution (to avoid that code in HomePage) would be
to pass a reference into the TagCloudPanel but then it wouldn't be reuseable ...
hmmh, maybe I'll create a subclass of TagCloudPanel ...
hmmh, maybe the private method trick is better :-)

Regards,
Peter.

**
tagCloud = new TagCloudPanel("tagcloud") {

@Override
protected void onTagClick(String name) {
if (lastQuery != null) {
lastQuery.setQuery((lastQuery.getQuery() + " " + name).trim());
doSearch(lastQuery, 0, true);
} else {
// never happens?
PageParameters pp = new PageParameters();
pp.add("q", name);
setResponsePage(HomePage.class, pp);
}
}

@Override
protected void onFindOriginClick(String tag) {
PageParameters pp = new PageParameters();
pp.add("findOrigin", tag);

doSearch(createQuery(pp), 0, true);
// this preserves parameters but cannot be context sensitive!
// setResponsePage(HomePage.class, pp);
}
};
add(tagCloud.setOutputMarkupId(true));


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.
       }
     });
   }
}


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

Reply via email to