I shall press ahead with storing the web-safe string of each cursor in a stack kept in the user's session object, and using this to provide backwards pagination.
On Jan 17, 8:31 pm, Ian Marshall <ianmarshall...@gmail.com> wrote: > Does anyone fancy exercising their little grey cells on this fine > Monday? > > I have an entity with relevant fields declared as: > > @PersistenceCapable(identityType = IdentityType.APPLICATION, > detachable = "true") > public class Thing implements Serializable > { > private static final long serialVersionUID = 1L; > > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > @Extension(vendorName="datanucleus", key="gae.encoded-pk", > value="true") > private String sEncodedKey; > > @Persistent > @Extension(vendorName="datanucleus", key="gae.pk-id", value="true") > private Long loID; > > @Persistent > private Date dtCreated; > > } > > I want to display pages of my persistent entity to the user, which > each page having, say, 20 items displayed. I want to use the class > JDOCursorHelper (and stick with JDO if possible). The GAE/J > documentation shows me how I can paginate forwards: > > · Query the first 21 entities and store in an ArrayList<Thing>. > · If 21 are returned, set a "there are more entities" flag and > discard the 21st entity from the list, otherwise reset the flag. > · Show the 20 entities. > · Store the cursor as a web-safe string. > · If the user hits "Next" (enabled if the flag is set) then: > · retrieve the cursor from the web-safe string. > · get the next 21 entities > · etc. > > The fun starts if I want to allow the user to paginate the previous > pages. One method that I can think of stores the web-safe string of > each cursor in a list kept in the user's session object. As "Next" is > hit, the cursor just generated can be pushed onto the list. To > traverse backwards, I pop (delete) the latest cursor string from the > session's list and then use the previous one (now the latest) to > produce the previous page's items. > > Can anyone think of a smarter way to paginate backwards without > storing a list of web-safe cursor strings in a user's session? > > (I could generate an additional persistent field which holds the > concatenated string values > > [dtCreated to milliseconds using Calendar] + "|" + sEncodedKey > > but the GAE/J article for this says that this way is no longer > recommended.) > > Regards, > > Ian -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.