Re: Cannot get current page from AjaxPagingNavigator
Ohh sorry, now that i read your code carefully i see you have a case of the Chicken and the Egg!! :) On Wed, Nov 10, 2010 at 11:30 AM, Juan Carlos Garcia wrote: > I would change: > final Label currentPage = new Label("currentPage", new Model()); > > to this: > Label currentPage = new Label("currentPage", new LoadableDetachableModel(){ > public Object load(){ > return pagination.getPageable().getCurrentPage() + 1; > > > } > > }); > > and then just remove the last part: > currentPage.setDefaultModel(model); > > On Wed, Nov 10, 2010 at 5:19 AM, vp143 [via Apache Wicket] < > ml-node+3035648-2145298352-65...@n4.nabble.com > > wrote: > >> I got it working with the following code- thanks Pedro and JC >> >> final Label currentPage = new Label("currentPage", new Model()); >> currentPage.setOutputMarkupId(true); >> add(currentPage); >> >> final AjaxPagingNavigator pagination = new >> AjaxPagingNavigator("navigator", dataList) { >> @Override >> protected void onAjaxEvent(AjaxRequestTarget target) { >> target.addComponent(currentPage); >> super.onAjaxEvent(target); >> } >> }; >> add(pagination); >> >> LoadableDetachableModel model = new LoadableDetachableModel() { >> public Object load(){ >> return pagination.getPageable().getCurrentPage() + 1; >> } >> }; >> currentPage.setDefaultModel(model); >> >> It had to be written like this because the model needs pagination which >> would not have been initialised if written as an inner class when creating >> the label. >> Please let me know if anyone finds a better way of writing it. >> >> Many thanks again >> Vishal >> >> -- >> View message @ >> http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3035648.html >> To start a new topic under Apache Wicket, email >> ml-node+1842946-398011874-65...@n4.nabble.com >> To unsubscribe from Apache Wicket, click >> here<http://apache-wicket.1842946.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>. >> >> >> > > > -- > Sincerely, > JC (http://www.linkedin.com/in/jcgarciam) > Work smarter, not harder!. > > -- Sincerely, JC (http://www.linkedin.com/in/jcgarciam) Work smarter, not harder!. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3036177.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Cannot get current page from AjaxPagingNavigator
I would change: final Label currentPage = new Label("currentPage", new Model()); to this: Label currentPage = new Label("currentPage", new LoadableDetachableModel(){ public Object load(){ return pagination.getPageable().getCurrentPage() + 1; } }); and then just remove the last part: currentPage.setDefaultModel(model); On Wed, Nov 10, 2010 at 5:19 AM, vp143 [via Apache Wicket] < ml-node+3035648-2145298352-65...@n4.nabble.com > wrote: > I got it working with the following code- thanks Pedro and JC > > final Label currentPage = new Label("currentPage", new Model()); > currentPage.setOutputMarkupId(true); > add(currentPage); > > final AjaxPagingNavigator pagination = new > AjaxPagingNavigator("navigator", dataList) { > @Override > protected void onAjaxEvent(AjaxRequestTarget target) { > target.addComponent(currentPage); > super.onAjaxEvent(target); > } > }; > add(pagination); > > LoadableDetachableModel model = new LoadableDetachableModel() { > public Object load(){ > return pagination.getPageable().getCurrentPage() + 1; > } > }; > currentPage.setDefaultModel(model); > > It had to be written like this because the model needs pagination which > would not have been initialised if written as an inner class when creating > the label. > Please let me know if anyone finds a better way of writing it. > > Many thanks again > Vishal > > -- > View message @ > http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3035648.html > To start a new topic under Apache Wicket, email > ml-node+1842946-398011874-65...@n4.nabble.com > To unsubscribe from Apache Wicket, click > here<http://apache-wicket.1842946.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>. > > > -- Sincerely, JC (http://www.linkedin.com/in/jcgarciam) Work smarter, not harder!. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3036168.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Cannot get current page from AjaxPagingNavigator
I got it working with the following code- thanks Pedro and JC final Label currentPage = new Label("currentPage", new Model()); currentPage.setOutputMarkupId(true); add(currentPage); final AjaxPagingNavigator pagination = new AjaxPagingNavigator("navigator", dataList) { @Override protected void onAjaxEvent(AjaxRequestTarget target) { target.addComponent(currentPage); super.onAjaxEvent(target); } }; add(pagination); LoadableDetachableModel model = new LoadableDetachableModel() { public Object load(){ return pagination.getPageable().getCurrentPage() + 1; } }; currentPage.setDefaultModel(model); It had to be written like this because the model needs pagination which would not have been initialised if written as an inner class when creating the label. Please let me know if anyone finds a better way of writing it. Many thanks again Vishal -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3035648.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Cannot get current page from AjaxPagingNavigator
I think you need to implement the AjaxPagingNavigator#onAjaxEvent method and add the currentPage component on target. On Tue, Nov 9, 2010 at 4:20 PM, vp143 wrote: > > Thank you both for your responses- I totally forgot about it being dynamic. > > However, I have tried both code snippets above but still no luck. > I printed the current page within the load() method which prints 0 only on > first load. No message is printed when the page numbers from > AjaxPagingNavigator are clicked on. > > Any thoughts? > Vishal > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3034840.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Pedro Henrique Oliveira dos Santos
Re: Cannot get current page from AjaxPagingNavigator
Thank you both for your responses- I totally forgot about it being dynamic. However, I have tried both code snippets above but still no luck. I printed the current page within the load() method which prints 0 only on first load. No message is printed when the page numbers from AjaxPagingNavigator are clicked on. Any thoughts? Vishal -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3034840.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Cannot get current page from AjaxPagingNavigator
Use an dinamic model, ex: Label currentPage = new Label("currentPage", new AbstractReadOnlyModel() { public String getObject() { return pagination.getPageable().getCurrentPage(); } }); On Tue, Nov 9, 2010 at 2:04 PM, Vishal Popat wrote: > Hi all, > > For some reason I cannot get the current page number. This is the relevant > part of my code: > > > > PageableListView dataList = new PageableListView("dataList", results, 10) { > >protected void populateItem(ListItem item) { > >.. > > } > >} > > > >AjaxPagingNavigator pagination = new > AjaxPagingNavigator("navigator", dataList); > >add(pagination); > > > >Label currentPage = new Label("currentPage", > pagination.getPageable().getCurrentPage() + ""); > >currentPage.setOutputMarkupId(true); > >add(currentPage); > > > > currentPage always returns 0. > > I have also tried PagingNavigator with similar results. > > > > Can anyone tell me what I have missed? > > > > Regards > > > > Vishal > > -- Pedro Henrique Oliveira dos Santos
Re: Cannot get current page from AjaxPagingNavigator
You are using an static model, which only knows about the value by the time of construction. Use a dynamic model i.e: (make sure you define pagination as final) Label currentPage = new Label("currentPage", new LoadableDetachableModel(){ public Object load(){ return pagination.getPageable().getCurrentPage(); } }); On Tue, Nov 9, 2010 at 1:04 PM, vp143 [via Apache Wicket] < ml-node+3034524-366758351-65...@n4.nabble.com > wrote: > Hi all, > > For some reason I cannot get the current page number. This is the relevant > part of my code: > > > > PageableListView dataList = new PageableListView("dataList", results, 10) { > > > protected void populateItem(ListItem item) { > > .. > > } > > } > > > > AjaxPagingNavigator pagination = new > AjaxPagingNavigator("navigator", dataList); > > add(pagination); > > > > Label currentPage = new Label("currentPage", > pagination.getPageable().getCurrentPage() + ""); > > currentPage.setOutputMarkupId(true); > > add(currentPage); > > > > currentPage always returns 0. > > I have also tried PagingNavigator with similar results. > > > > Can anyone tell me what I have missed? > > > > Regards > > > > Vishal > > > > -- > View message @ > http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3034524.html > To start a new topic under Apache Wicket, email > ml-node+1842946-398011874-65...@n4.nabble.com > To unsubscribe from Apache Wicket, click > here<http://apache-wicket.1842946.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>. > > > -- Sincerely, JC (http://www.linkedin.com/in/jcgarciam) Work smarter, not harder!. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Cannot-get-current-page-from-AjaxPagingNavigator-tp3034524p3034563.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Cannot get current page from AjaxPagingNavigator
Hi all, For some reason I cannot get the current page number. This is the relevant part of my code: PageableListView dataList = new PageableListView("dataList", results, 10) { protected void populateItem(ListItem item) { .. } } AjaxPagingNavigator pagination = new AjaxPagingNavigator("navigator", dataList); add(pagination); Label currentPage = new Label("currentPage", pagination.getPageable().getCurrentPage() + ""); currentPage.setOutputMarkupId(true); add(currentPage); currentPage always returns 0. I have also tried PagingNavigator with similar results. Can anyone tell me what I have missed? Regards Vishal