a)
class mypanel extends panel {
mypanel () {
add(new listview() { onpopulateitem(item) {
mypanel.this.onpopulateitem(): }{});
}
protected abstract onpopulateitem(item);
}
b) instead of trying to encapsulate both the listview and the button
in the component make a reusable button
class listviewcollapsebutton extends button {
private listview view;
private boolean expanded=true;
onsubmit() { expanded=!expanded; if (expanded)
view.setitemsperpage(100); else {view.setitemsperpage(5);}
view.setcurrentpage(0); }
}
then its as easy as new listviewcollapsebutton("collapse", listview);
-igor
On Thu, Jul 7, 2011 at 4:50 PM, T P D <[email protected]> wrote:
> I want to add several "collapsable" ListViews: a listview paired with a
> button to toggle showing either the full list or the fist N elements.
>
> But each listview's populateItem and corresponding markup will be different.
>
> If I write a Wicket Panel, I'm not only "locked-in" to one set of markup.
>
> I must also new up the ListView in the Panel's constructor, which means I
> can't vary the code in ListView's overridden anonymous-class populateItem,
> as I could if I passed in ListView instance.
>
> MyPanel() {
> add( new ListView("someid") {
> void populateItem( ListItem i ) {
> i.add( new Label("foo") ...
>
>
>
> If I instead pass in the ListView, then any user of my Panel class can pass
> in any instance or anonymous instance of ListView -- but my Panel can't call
> listView.setId() on the already constructed ListView to make its id match
> the id in the Panel's markup.
>
> This seems like a simple thing, make two components collaborators and make
> that reusable, but the only way to do it seems to be to write a
> WebMarkupContainer-derived class, and pass in the ids, rather than writing a
> Panel.
>
> is there a simpler way I'm not seeing?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]