You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Malcolm Edgar <ma...@gmail.com> on 2010/03/04 09:42:44 UTC

Re: Table throws exception when the amount of retrieved data is less than its page size

How are you getting your source data?
* Cayenne
* Hibernate
* JDBC

regards Malcolm Edgar

On Thu, Mar 4, 2010 at 7:32 PM, Bob Schellink <sa...@gmail.com> wrote:
> Hi Kristian,
>
> I just tested the large data demo and it seems to work correctly:
>
>    // Return count of 2
>    private int getCustomerCount() {
>        return 2;
>    }
>
>    // Return 2 hardcoded customers
>    private List<Customer> getCustomers(int from, int pageSize, String
> sortedColumn,
>        boolean ascending) {
>
>        List customers = new ArrayList();
>        Customer customer = new Customer();
>        customer.setName("test");
>        customers.add(customer);
>
>        customer = new Customer();
>        customer.setName("test");
>        customers.add(customer);
>        return customers;
>    }
>
> kind regards
>
> bob
>
>
> On 4/03/2010 06:30 PM, kristian_widjaja wrote:
>>
>> Hi all,
>>
>> I am currently developing a webapp using Click 2.1.0. Anyway, according to
>> my project reqs, there are pages that needs to display data in a
>> pagination
>> way. And i've had click examples "large dataset demo" implemented in my
>> project.
>>
>> So, when i didn't use "DataProvider" class as a data adapter, it works
>> fine
>> when the amount of retrieved data is less than the table's pageSize.
>>
>> The problem is, when i used the "DataProvider" to perform pagination and
>> the
>> amount of retrieved data is less than the table's pageSize, the
>> IndexOutOfBoundsException is thrown by the page when rendering the page.
>> For
>> example :
>>
>> <code>
>> public ProfilePage() {
>>        ...
>>
>>        table.setPageSize(10);
>>        table.setSortable(true);
>>        table.setSorted(true);
>>        ...
>> }
>>
>> @Override
>> public void onRender() {
>>        log.debug("# Rendering Profile Page...");
>>        if (hasPreservedState()) {
>>            DataProvider dataProvider = new DataProvider(table,
>> getMemberUsersRecordCount());
>>            table.setRowList(dataProvider);
>>
>>            List<MemberUsers>  memberUsersList = getMemberUsersList(); //
>> e.g. only
>> 5 records
>>            dataProvider.addAll(memberUsersList);
>>        }
>> }
>> </code>
>>
>> The method 'getMemberUsersRecordCount()' is returning value of '5', so
>> when
>> retrieving the data, method 'getMemberUsersList()' only returning 5
>> records.
>>
>> Is there anyone ever having the same problem? Or is there any posting from
>> another user?
>> Thanks.
>
>

Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by kristian_widjaja <kr...@yahoo.com>.
Hi, henry

Sure, here is the code : 

<code>
private int getMemberUsersRecordCount() { // getLoggedInUserName() = e.g.
'12341234'
	return memberUsersService.getUserCountByVirtualId(getLoggedInUserName());
}

public class MemberUsersService implement MemberUsersService {
        ...
        public List<MemberUsers> getUsersListByVirtualId(String virtualId)
throws Exception {
		log.debug("# Get user list by virtual id: " + virtualId);

		MemberUsersCriteria criteria = new MemberUsersCriteria();
		criteria.createCriteria().andVirtualIdEqualTo(virtualId);

		return memberUsersDAO.selectMemberUsersByExample(criteria);
	}
}
</code>

And this is the query in file MemberUsersService_sqlmap.xml : 

<code>
<select id="ibatorgenerated_countByExample"
parameterClass="com.gng.db.core.ibatis.entity.MemberUsersCriteria"
resultClass="java.lang.Integer">
    <!--
      WARNING - This element is automatically generated by Apache iBATIS
ibator, do not modify.
      This element was generated on Wed Mar 03 21:40:17 ICT 2010.
    -->
    select count(*) from GNGUSER.MEMBER_USERS
    <include
refid="GNGUSER_MEMBER_USERS.ibatorgenerated_Example_Where_Clause" />
  </select>
</code>

** where the '<include ' will be replaced by : "WHERE VIRTUAL_ID =
#virtualId#".

Regards,
Kristian W.
-- 
View this message in context: http://n2.nabble.com/Table-throws-exception-when-the-amount-of-retrieved-data-is-less-than-its-page-size-tp4672850p4673468.html
Sent from the click-user mailing list archive at Nabble.com.

Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by Henry Saputra <he...@gmail.com>.
Hi Kristian,

Could you post your code for "getMemberUsersRecordCount" ?

Maybe you have something like offset*AppConstants.PAGING_COUNT which makes
DataProvider.size() larger than actual data available.

- Henry

On Thu, Mar 4, 2010 at 1:49 AM, kristian_widjaja <
kristian_widjaja2@yahoo.com> wrote:

>
> Hi Bob,
>
> I was doing a litle magic and it fixed already, just did by setting the
> value of 'pageSize' property from click.Table the same as my own variable
> page size 'PAGING_COUNT'. It works fine now.
>
> But why is that the values of those variable has to be the same?
>
> Regards,
> Kristian W.
> --
> View this message in context:
> http://n2.nabble.com/Table-throws-exception-when-the-amount-of-retrieved-data-is-less-than-its-page-size-tp4672850p4673295.html
> Sent from the click-user mailing list archive at Nabble.com.
>

Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by kristian_widjaja <kr...@yahoo.com>.
Hi Bob,

I was doing a litle magic and it fixed already, just did by setting the
value of 'pageSize' property from click.Table the same as my own variable
page size 'PAGING_COUNT'. It works fine now. 

But why is that the values of those variable has to be the same?

Regards,
Kristian W.
-- 
View this message in context: http://n2.nabble.com/Table-throws-exception-when-the-amount-of-retrieved-data-is-less-than-its-page-size-tp4672850p4673295.html
Sent from the click-user mailing list archive at Nabble.com.

Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by Bob Schellink <sa...@gmail.com>.
The LargeDataSet demo DataProvider is a bit of a hack as it overrides the ArrayList size method to 
return a number much larger than the actual amount of rows. The #get method must then deduct the 
correct offset from the index to retrieve the correct record. If you debug the DataProvider #get and 
#size methods it should give insight as to what is happning.

kind regards

bob


On 4/03/2010 08:29 PM, kristian_widjaja wrote:
>
> Ok, thanks Bob. Well, there must be something wrong with code then. I'll try
> to fix it first.
>
> Regards,
> Kristian W.


Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by kristian_widjaja <kr...@yahoo.com>.
Ok, thanks Bob. Well, there must be something wrong with code then. I'll try
to fix it first.

Regards,
Kristian W.
-- 
View this message in context: http://n2.nabble.com/Table-throws-exception-when-the-amount-of-retrieved-data-is-less-than-its-page-size-tp4672850p4673220.html
Sent from the click-user mailing list archive at Nabble.com.

Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by Bob Schellink <sa...@gmail.com>.
Yep, I did the test with LargeDatasetDemo which has a pagesize of 5.

kind regards

bob

On 4/03/2010 08:09 PM, kristian_widjaja wrote:
>
> Hi, Bob and Malcolm. Thanks for replying.
>
> To Bob,
> Have you tried to set the pageSize larger than the actual amount of
> available data by using "DataProvider"? Cause the problem arise when that
> strategy is implemented.
>
> To Malcolm,
> I am using JDBC wrapped by iBatis. Method to retrieved the list of data is
> below :
>
> <code>
> private List<MemberUsers>  getMemberUsersList() {
> 		int offset = 1;
>
> 		if (StringUtils.hasLength(page)) {
> 			int pageNumber = Integer.parseInt(page);
> 			offset = pageNumber * AppConstants.PAGING_COUNT; // PAGING_COUNT = 10;
> 		}
>
> 		return memberUsersService.getUsersListByVirtualId(
> 				getPreservedState().toString(), offset, AppConstants.PAGING_COUNT);
> 	}
> </code>
>
>
> The query is listed below:
>
> <code>
> select USER_ID, VIRTUAL_ID, JOIN_DT, STATUS, NAME, BIRTH_DT, EMAIL, PHONE,
> UPLINE
>      from ( select a.USER_ID, a.VIRTUAL_ID, a.JOIN_DT, a.STATUS, a.NAME,
> a.BIRTH_DT, a.EMAIL,
>      			  a.PHONE, a.UPLINE, rownum rnum
>             from (
>             		select USER_ID, VIRTUAL_ID, JOIN_DT, STATUS, NAME, BIRTH_DT,
> EMAIL, PHONE, UPLINE
>      	 		from GNGUSER.MEMBER_USERS
>              ) a
>             where rownum<= #maxRows#
>           )
>      where rnum>= #minRows#
> </code>
>
> Anyway, as available records only 5 records currently, so when i set the
> 'pageSize = 5' and constant 'PAGING_COUNT = 5', it works well. As i
> mentioned before, only when i set 'pageSize' larger than actual available
> data count then the exception is thrown. Thanks.
>
> Regards,
> Kristian Widjaja.


Re: Table throws exception when the amount of retrieved data is less than its page size

Posted by kristian_widjaja <kr...@yahoo.com>.
Hi, Bob and Malcolm. Thanks for replying.

To Bob, 
Have you tried to set the pageSize larger than the actual amount of
available data by using "DataProvider"? Cause the problem arise when that
strategy is implemented.

To Malcolm,
I am using JDBC wrapped by iBatis. Method to retrieved the list of data is
below : 

<code>
private List<MemberUsers> getMemberUsersList() {
		int offset = 1;

		if (StringUtils.hasLength(page)) {
			int pageNumber = Integer.parseInt(page);
			offset = pageNumber * AppConstants.PAGING_COUNT; // PAGING_COUNT = 10;
		}

		return memberUsersService.getUsersListByVirtualId(
				getPreservedState().toString(), offset, AppConstants.PAGING_COUNT);
	}
</code>


The query is listed below: 

<code>
select USER_ID, VIRTUAL_ID, JOIN_DT, STATUS, NAME, BIRTH_DT, EMAIL, PHONE,
UPLINE
    from ( select a.USER_ID, a.VIRTUAL_ID, a.JOIN_DT, a.STATUS, a.NAME,
a.BIRTH_DT, a.EMAIL, 
    			  a.PHONE, a.UPLINE, rownum rnum
           from (
           		select USER_ID, VIRTUAL_ID, JOIN_DT, STATUS, NAME, BIRTH_DT,
EMAIL, PHONE, UPLINE
    	 		from GNGUSER.MEMBER_USERS 
            ) a
           where rownum <= #maxRows# 
         )
    where rnum >= #minRows#
</code>

Anyway, as available records only 5 records currently, so when i set the
'pageSize = 5' and constant 'PAGING_COUNT = 5', it works well. As i
mentioned before, only when i set 'pageSize' larger than actual available
data count then the exception is thrown. Thanks.

Regards,
Kristian Widjaja.
-- 
View this message in context: http://n2.nabble.com/Table-throws-exception-when-the-amount-of-retrieved-data-is-less-than-its-page-size-tp4672850p4673121.html
Sent from the click-user mailing list archive at Nabble.com.