Re: inmethod grid cachedPageCount

2013-03-04 Thread Ciocoiu Elvis
Thank you Paul,

But in my case I'm using IDataSource from immethod grid to retrieve the
current page. In client code after inserting the new record in the database
I'm obtaining the corresponding page number (greater than the one cached by
inmethod grid) and let the grid display itself (internally calls get page
from IDataSource). What I need is the easiest way to update the inmethod
grid to know that there is one more page). The most appropiate idea was to
set the current grid page to the last one but even if the grid let me do
that through its api (used also by the navigator) crashes because of this
internally cached page count. All the logic to retrieve the page based on
the current sort and filter is implemented. I don't want to change the
widget for the moment (inmethod grid is ok except this usecase) so I must
stick to IDataSource and it's usage.
On Feb 28, 2013 3:50 AM, "Paul Bors"  wrote:

> Well, reading your post a second time around...
>
> If you really want to add a record and then paginate to the page that
> contains it, you'd have to re-run your SQL right?
>
> I think it would make more sence to KISS it. Change your DataProvider by
> re-running the SQL and provide the record ID (primary key, hash or
> something
> unique to your new saved record) then add a new constructor for your table
> or DataProvider to handle the pagination by looking through your collection
> for the element with that unique ID page by page or by implementing the
> pagination in SQL (search with the record ID given your fileters and sort
> order and forward your cursor to the page that contains your record).
>
> Mersi mult, si chiar am nevoie mare :)
>
>
>
> -
> ~ Thank you,
>     p...@bors.ws
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/inmethod-grid-cachedPageCount-tp4656739p4656875.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: inmethod grid cachedPageCount

2013-02-27 Thread Paul Bors
Well, reading your post a second time around...

If you really want to add a record and then paginate to the page that
contains it, you'd have to re-run your SQL right?

I think it would make more sence to KISS it. Change your DataProvider by
re-running the SQL and provide the record ID (primary key, hash or something
unique to your new saved record) then add a new constructor for your table
or DataProvider to handle the pagination by looking through your collection
for the element with that unique ID page by page or by implementing the
pagination in SQL (search with the record ID given your fileters and sort
order and forward your cursor to the page that contains your record).

Mersi mult, si chiar am nevoie mare :)



-
~ Thank you,
p...@bors.ws
--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/inmethod-grid-cachedPageCount-tp4656739p4656875.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: inmethod grid cachedPageCount

2013-02-25 Thread Paul Bors
I once implemented something similar where I had to add records to a
DataTable.
What I ended up doing is twickying the DataProvider to allow adding rows to
the current page.

ie: I would add new rows to the current page and flush them to the DB on
Save.
I did not have to care about the page number nor the sort order as the rows
were always added to the current page, top row and the table would grow in
size with each additonal record. Once pagination happen, the rows would be
sorted anyhow and displayed in the proper place.

Below are the changes to my parent DataTable that I had to implement to
make this possible (feel free to use as you see fit):
/**
 * Obtain the index of the first row on the given page number.
 *
 * @param pageNum The page number for which to retrieve the index
within the List model.
 * @return The first row index on the given page number if that page
were to be rendered.
 */
public int getIndexOfFirstRowOnPage(int pageNum) {
return (pageNum > 0) ? pageNum * getItemsPerPage() : 0;
}

/**
 * Obtain the index of the last row on the given page number.
 *
 * @param pageNum The page number for which to retrieve the index
within the List model.
 * @return The last row index on the given page number if that page
were to be rendered.
 */
public int getIndexOfLastRowOnPage(int pageNum) {
int rowsPerPage = getItemsPerPage();
int totalRows   = getRowCount();
int lastRow= (pageNum > 0) ? (pageNum * rowsPerPage) +
rowsPerPage -1 : rowsPerPage - 1;
if(lastRow >= totalRows) {
lastRow = totalRows - 1;
}
return lastRow;
}

/**
 * Retrieve collection of the row models for the given page
number.
 * NOTE: Is more efficient to build your own collection of
elements on
 * a page by adding them during one of your columns populateItem()
call.
 *
 * @param pageNum The page number for which to retrieve the collection
of rows.
 * @return  A list of models found on the given page number, null if
the page
 *  number is invalid.
 */
@SuppressWarnings("unchecked")
public List getRowsOnPage(int pageNum) {
int rowsPerPage = getItemsPerPage();
int totalRows   = getRowCount();
int firstRow= (pageNum > 0) ? pageNum * rowsPerPage : 0;
int count   = (rowsPerPage > totalRows) ? totalRows :
rowsPerPage;
int lastRow = firstRow + count;
if( lastRow > totalRows) {
count = rowsPerPage - (lastRow - totalRows);
}

if((pageNum > totalRows/rowsPerPage) || (pageNum < 0) ) {
return null;
}

List elements = new ArrayList();
Iterator iter = (Iterator) provider.iterator(firstRow, count);
while(iter.hasNext()) {
elements.add(iter.next());
}
return elements;
}

Noroc si bafta la treaba!

~ Thank you,
   Paul Bors

On Sun, Feb 24, 2013 at 9:02 AM, Ciocoiu Elvis
wrote:

> Hi,
>
> I'm trying to select a item of inmethod grid after adding it in an ajax
> call. Based on the current sort properties and filters, after I effectively
> add the element in the database but in the same ajax call I'm determining
> the element's page number and try to set it as current page in the grid. My
> code works except in the case when the created element is in the last page
> (the current grid page page count is cached internally in
> AbstractPageableView.cachedPageCount). In this case the cachedPageCount is
> equal to the create element page and when calling
> grid.setCurrentPage(newPage) { ... if (page < 0 || page >= pageCount &&
> pageCount > 0) ... } throws IndexOutOfBounds exception. I want to clear the
> cachedPageCount somehow ... or maybe there is another solution? I want to
> select the new page in the same ajax call. For the moment if I encounter
> this situation I select the previous page ... but the my newly created
> element is on the next one :(
>
> Can somebody help me with some hints?
>
> Thank you
>
> --
> _
> Elvis Ciocoiu
> Senior Consultant
>
> Synthesys Consulting ROMANIA
>
> address: http://www.synthesys.ro
> e-mail: elvis.cioc...@synthesys.ro
> mobile : (40) 0745 13 75 85
>
> This message and any attachments contain information, which may be
> confidential or privileged.
> If you are not the intended recipient, please refrain from any
> disclosure, copying, distribution or use of this information.
> Please be aware that such actions are prohibited. If you have received
> this transmission in error, kindly notify us by email to
> off...@synthesys.ro. We appreciate your cooperation.
>


inmethod grid cachedPageCount

2013-02-24 Thread Ciocoiu Elvis
Hi,

I'm trying to select a item of inmethod grid after adding it in an ajax
call. Based on the current sort properties and filters, after I effectively
add the element in the database but in the same ajax call I'm determining
the element's page number and try to set it as current page in the grid. My
code works except in the case when the created element is in the last page
(the current grid page page count is cached internally in
AbstractPageableView.cachedPageCount). In this case the cachedPageCount is
equal to the create element page and when calling
grid.setCurrentPage(newPage) { ... if (page < 0 || page >= pageCount &&
pageCount > 0) ... } throws IndexOutOfBounds exception. I want to clear the
cachedPageCount somehow ... or maybe there is another solution? I want to
select the new page in the same ajax call. For the moment if I encounter
this situation I select the previous page ... but the my newly created
element is on the next one :(

Can somebody help me with some hints?

Thank you

-- 
_
Elvis Ciocoiu
Senior Consultant

Synthesys Consulting ROMANIA

address: http://www.synthesys.ro
e-mail: elvis.cioc...@synthesys.ro
mobile : (40) 0745 13 75 85

This message and any attachments contain information, which may be
confidential or privileged.
If you are not the intended recipient, please refrain from any
disclosure, copying, distribution or use of this information.
Please be aware that such actions are prohibited. If you have received
this transmission in error, kindly notify us by email to
off...@synthesys.ro. We appreciate your cooperation.