Friday, June 3, 2011

Query URL transformation

From "Matering Dojo" p275

But different server-side programs
require different forms of URLs.

For example:
mystore.php?query=A%&page=1&itemsperpage=10&sort=name

Rather than be dictatorial, QueryReadStore allows you to plug in code to
rewrite the dojo.data request as a URL. You do this by writing a subclass
of QueryReadStore and using that for your driver instead.


dojo.provide("dojobook.data.datasources.sample_rewriter" );

dojo.require("dojox.data.QueryReadStore" );

dojo.declare(
"dojobook.data.datasources.sample_rewriter" ,
dojox.data.QueryReadStore, {

fetch:function(request) {
request.serverQuery = {
q: request.query.substance.replace("*" , "%" ),
itemsperpage: request.count,
page: Math.floor(request.start / 10)
};

// Call superclasses' fetch
return this.inherited(arguments);
}
});

QueryReadStore sends both the request.query and the request.serverQuery
properties combined. In the previous example, mystore.php?q=A&page=10&
itemsperpage=10&query=A*&start=1&count=10 gets sent. As long as the extra
parameters do not interfere with the server program, you needn’t worry
about it. If they do, you can simply null out request.query.field in the
QueryReadStore subclass

No comments:

Post a Comment