Ok, got it working, thanks to igor.  Here is the code for Wicket version
1.2.3 that dynamically updates the rowsPerPage for a given DataTable:

        List rows = Arrays.asList(new String[] {"5", "10", "15", "20"});

        add(new DropDownChoice("rows", new IModel() {
            public void setObject(Component component, Object e) {
                Integer rows = Integer.parseInt((String) e);
                contacts.setRowsPerPage(rows);
            } 
            public Object getObject(Component component) {return
contacts.getRowsPerPage();} 
            public void detach(){}
            public IModel getNestedModel() {return null;}
        }, rows) {
            @Override
            protected boolean wantOnSelectionChangedNotifications() {
                return true;
            }
        }); 


janders wrote:
> 
> Thank you, I will review the models page on the wiki.  If I can figure out
> a working solution I will post it here.  
> 
> This certainly seems like a good candidate for a DataTable Toolbar so that
> developers can easily add a dropdown to allow users to change the number
> of rows displayed.
> 
> - JA
> 
> 
> 
> igor.vaynberg wrote:
>> 
>> On 8/27/07, janders <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>> I understand, but being a newbie, this makes little sense.  Where is
>>> wantOnSelectionChangedNotifications()
>>> and onSelectionChanged().  Aren't these require?
>> 
>> 
>> only if you want the selection updated right after selecting a new value
>> in
>> the dropdown
>> 
>> How does the selection
>>> value get passed to rowsPerPage?  Can you point me to a working example?
>> 
>> 
>> im afraid i dont know of any cases that do this exact thing. what i have
>> shown you should work, i suggest you read the models page on the wiki.
>> 
>> -igor
>> 
>> 
>> 
>> BTW, I'm currently using Wicket 1.2.3.
>>>
>>>
>>>
>>> igor.vaynberg wrote:
>>> >
>>> > heh, you have to meet us half way here. you cant expect to be able to
>>> > paste
>>> > pseudocode into the ide and have it compile and work.
>>> >
>>> > the int[] param is intended to be the third constructor param of
>>> > dropdownchoice not the second param of add().
>>> >
>>> > if you are using an older wicket ver - 1.2 then imodel has an extra
>>> > component param which you can ignore
>>> >
>>> > my point is: look at what the example is trying to do.
>>> >
>>> > -igor
>>> >
>>> >
>>> > On 8/27/07, janders <[EMAIL PROTECTED]> wrote:
>>> >>
>>> >>
>>> >> I'm new to wicket and I fail to see how the proposed solution
>>> >> works.  Coping
>>> >> this into the IDE, and even after correcting for caps, there are
>>> several
>>> >> errors.  For one, add takes a component, not a component plus int[].
>>> >> Also
>>> >> IModel wanted to implement unimplemented methods. What I'm I missing?
>>> >>
>>> >>
>>> >>
>>> >> igor.vaynberg wrote:
>>> >> >
>>> >> > class mypage() {
>>> >> >   static int[] pages=new int[] {10,15,20,25};
>>> >> >
>>> >> >   public mypage () {
>>> >> >     final DataTable dt=new datatable(..);
>>> >> >
>>> >> >    add(new dropdownchoice("pages", new imodel() {
>>> >> >        void setObject(Object e) { dt.setrowsperpage((Integer)e); }
>>> >> >        Object getObject() { return td.getrowsperpage(); }
>>> >> >        void detach() {}), pages);
>>> >> > }
>>> >> >
>>> >> > -igor
>>> >> >
>>> >> >
>>> >> > On 8/26/07, janders <[EMAIL PROTECTED]> wrote:
>>> >> >>
>>> >> >>
>>> >> >> The format of the Exception got munged with the example code. This
>>> >> should
>>> >> >> read as:
>>> >> >>
>>> >> >> IllegalStateException: Attempt to set model object on null model
>>> of
>>> >> >> component: rows
>>> >> >>
>>> >> >> final DataTable contacts = NEWDataTable("contacts", columns,
>>> >> >> contactProvider, rowsPerPage) {
>>> >> >>     @Override
>>> >> >>     PROTECTEDItem newRowItem(String id, INTindex, IModel model) {
>>> >> >>         RETURNNEWOddEvenItem(id, index, model);
>>> >> >>     }
>>> >> >> };
>>> >> >>
>>> >> >>
>>> >> >> janders wrote:
>>> >> >> >
>>> >> >> > I would like to be able to add a dropdown to a DataTable so that
>>> a
>>> >> user
>>> >> >> > can change the rowsPerPage.  Has anyone done this before?  If
>>> not,
>>> >> what
>>> >> >> is
>>> >> >> > the best / recommended approach?
>>> >> >> > I tried the following, but I get:
>>> >> >> >
>>> >> >> > IllegalStateException: Attempt to set model object on null model
>>> of
>>> >> >> > component: rowsFINALDataTable contacts =
>>> NEWDataTable("contacts",
>>> >> >> columns,
>>> >> >> > contactProvider, rowsPerPage) {
>>> >> >> >     @Override
>>> >> >> >     PROTECTEDItem newRowItem(String id, INTindex, IModel model)
>>> {
>>> >> >> >         RETURNNEWOddEvenItem(id, index, model);
>>> >> >> >     }
>>> >> >> > };
>>> >> >> >
>>> >> >> > List rows = Arrays._asList_(NEWString[] {"5", "10", "15", "20",
>>> >> >> "all"});
>>> >> >> > add(NEWDropDownChoice("rows", rows) {
>>> >> >> >     @Override
>>> >> >> >     PROTECTEDBOOLEANwantOnSelectionChangedNotifications() {
>>> >> >> >         RETURNTRUE;
>>> >> >> >     }
>>> >> >> >     @Override
>>> >> >> >     PROTECTEDVOIDonSelectionChanged(FINALObject newSelection) {
>>> >> >> >         IF(newSelection == "all") {
>>> >> >> >             contacts.setRowsPerPage(100000); // use really big
>>> >> number
>>> >> >> to
>>> >> >> > display all
>>> >> >> >         } ELSE{
>>> >> >> >             contacts.setRowsPerPage((Integer) newSelection);
>>> >> >> >         }
>>> >> >> >     }
>>> >> >> > });
>>> >> >> >
>>> >> >> > - JA
>>> >> >> >
>>> >> >> >
>>> >> >> >
>>> >> >>
>>> >> >> --
>>> >> >> View this message in context:
>>> >> >>
>>> >>
>>> http://www.nabble.com/DataTable-with-DropDownChoice-to-set-rowsPerPage-tf4332526.html#a12339585
>>> >> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>>> >> >>
>>> >> >>
>>> >> >>
>>> ---------------------------------------------------------------------
>>> >> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> >> >> For additional commands, e-mail: [EMAIL PROTECTED]
>>> >> >>
>>> >> >>
>>> >> >
>>> >> >
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://www.nabble.com/DataTable-with-DropDownChoice-to-set-rowsPerPage-tf4332526.html#a12361849
>>> >> Sent from the Wicket - User mailing list archive at Nabble.com.
>>> >>
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> >> For additional commands, e-mail: [EMAIL PROTECTED]
>>> >>
>>> >>
>>> >
>>> >
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/DataTable-with-DropDownChoice-to-set-rowsPerPage-tf4332526.html#a12362157
>>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/DataTable-with-DropDownChoice-to-set-rowsPerPage-tf4332526.html#a12388170
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to