Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Pagination in data service not working

Avatar

Level 1
Objective is to show a predefined number of records from the
database and

Populate a datagride.Say there are 50 records in the
database and the

requirement is to show 10 at time. As per documentaion
JavaAdaper needs to be used with page size defined. Tried but it
always return all the rows.



Code:



Mxml file



<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns="*" pageTitle="Contact Manager"
creationComplete="initApp()">

<mx:Script>

<![CDATA[

import samples.contact.*;

[Bindable]

public var contacts:ArrayCollection;

[Bindable]

public var contact:Contact;

private var ds:DataService;

private function initApp():void

{

var i:int;

contacts = new ArrayCollection();

ds = new DataService("contact");

ds.pageSize=4;

ds.autoCommit = false;

ds.fill(contacts);

AsyncToken(ds.fill(contacts));

token.kind = "fill";

}

]]>

</mx:Script>



<mx:DataGrid id="dg" dataProvider="{contacts}"
width="100%" height="100%"
change="contact=Contact(dg.selectedItem)" editable="true" >

<mx:columns>

<mx:DataGridColumn dataField="contactId"
headerText="Id"/>

<mx:DataGridColumn dataField="firstName"
headerText="First Name"/>

<mx:DataGridColumn dataField="lastName" headerText="Last
Name"/>

</mx:columns>

</mx:DataGrid>



Flex-data-service.xml



<destination id="contact">



<adapter ref="java-dao" />



<properties>


<source>samples.contact.ContactAssembler</source>

<scope>request</scope>



<metadata>

<identity property="contactId"/>

</metadata>



<network>

<session-timeout>2</session-timeout>

<paging enabled="true" pageSize="10"/>

<throttle-inbound policy="ERROR" max-frequency="500"/>

<throttle-outbound policy="REPLACE"
max-frequency="500"/>

</network>



<server>

<fill-method>

<name>loadContacts</name>

</fill-method>



<fill-method>

<name>loadContacts</name>

<params>java.lang.String</params>

</fill-method>



<sync-method>

<name>syncContacts</name>

</sync-method>

</server>

</properties>

</destination>





1 Reply

Avatar

Level 2
This all looks ok to me. If the data grid is displaying all
50 rows, you will see all 50 and might not notice that it was
actually fetching them 10 rows at a time. To see more about what
the server is sending to the client, enable the debug logging in
the server. Go to your services-config.xml (in WEB-INF/flex) and
search for "level=". Change that to Debug and make sure your
<pattern> tags just below that include both "DataService.*"
and "Message.*". When you run the application, you should see
something like:



[Flex] [DEBUG] Before invoke service: data-service

incomingMessage: Flex Message
(flex.data.messages.DataMessage)

operation = fill

id = null

clientId = 5BA19DE7-635A-5F00-819D-AD0AEB206647

correlationId =

destination = contact

messageId = E6389592-D861-9753-1792-AD0AEB20638E

timestamp = 1153954409497

timeToLive = 0

body =

[



]

hdr(DSEndpoint) = my-rtmp

hdr(pageSize) = 4





and then:



[Flex] [DEBUG] After invoke service: data-service

reply: Flex Message (flex.data.messages.PagedMessage)

sequenceId = 0

sequenceSize = 13

(no sequence proxies)

clientId = null

correlationId = null

destination = contact

messageId = F27873A5-264C-C0AC-E9E3-C625EE3FEA61

timestamp = 1153954430598

timeToLive = 0

body =

[

[contactId=3, firstName=Randy, lastName=Carter, address=,
phone=555-555-55

55, zip=],

[contactId=12, firstName=Mary, lastName=Connors, address=,
phone=, zip=],

[contactId=5, firstName=Pierre, lastName=Dupont, address=,
phone=222-222-2

222, zip=],

[contactId=7, firstName=Jose, lastName=Espinosa, address=,
phone=, zip=]

]



[Flex] [DEBUG] Before invoke service: data-service

incomingMessage: Flex Message
(flex.data.messages.DataMessage)

operation = page

id = null

clientId = C406259D-7A45-269E-CB51-AD0B3E282DE1

correlationId =

destination = contact

messageId = F3E58955-27D9-8AF9-5A7C-AD0B3EC48421

timestamp = 1153954430722

timeToLive = 0

body = {}

hdr(DSEndpoint) = my-rtmp

hdr(sequenceId) = 0

hdr(pageIndex) = 1

hdr(pageSize) = 4



[Flex] [DEBUG] After invoke service: data-service

reply: Flex Message (flex.data.messages.PagedMessage)

sequenceId = 0

sequenceSize = 13

(no sequence proxies)

clientId = null

correlationId = null

destination = contact

messageId = F27874D3-E208-C26D-A448-B9AFE682B86D

timestamp = 1153954430722

timeToLive = 0

body =

[

[contactId=10, firstName=Luis, lastName=Fernandez, address=,
phone=, zip=]

,

[contactId=15, firstName=Paula, lastName=Green, address=,
phone=, zip=],

[contactId=11, firstName=Chloe, lastName=Jones, address=,
phone=, zip=],

[contactId=9, firstName=Zoe, lastName=King, address=,
phone=, zip=]

]



Notice that there is first a "fill" message which returns 4
rows, then a page message which returns the next 4 rows. Try making
your initial window smaller and hit "refresh" and then you should
only see those page messages go across when you scroll.