| Sesat > Docs + Support > Development using the SFC > Tutorial - Ajax examples |
The RunningQueryImpl has a number of supported parameters that, in combination with using various layouts per tab (which can also be called a "vertical"), can be used to build a rich ajax client.
Each tab/vertical has a connection to one mode. In this mode there is a list of commands to run. By default all commands are run unless they are associated to enrichments from the tab, and the enrichment's rule achieved a score meeting the enrichment's threshold. Enough about enrichments, that's a story for another day.
This default behavior of which commands to run within the RunningQueryImpl can be explicitly, and per request, defined via the "commands" parameter.
For example, this search asks for only the defaultSearch command to run on sesam.no which is why you see "?" for the hit count on all the other services. The commands parameter takes a comma separate list when you want to request multiple commands within the mode to be run.
By default the RunningQueryImpl waits until all commands have been executed. This need not be the case though if you give, in modes.xml, the command the attribute asynchronous="true". If a command is attributed such and you want to be guaranteed to see the results you must explicitly state that you are willing to wait for the command to finished by adding the parameter for example waitFor=defaultSearch.
The waitFor parameter can be used in a number of ways:
Finally all this can be used with alternative layouts by suppling the layout parameter.
Each tab contains a default layout that is in views.xml the tab without an id attribute. With the layout parameter defined a layout with a matching id is looked for and used instead. If it can't be found the default is still used.
This allows a pseudo "portals" approach to the templating system. For example the request http://sesam.no/search/?q=sesat&commands=defaultSearch&layout=defaultSearchlayout
with the additional layout
<layout id="defaultSearchLayout" main="/fragments/layout/results/defaultSearch"/>
would render only the main results list on the page.
This above given layout doesn't have any embedded include templates. Since the result list is all rendered with just defaultSearch.vm template it can be supplied directly, in an absolute manner (see the initial / in the path), as the main template.
This section won't include much code, but will explain in more detail how AJAX can be used. For these examples we'll use the following configuration:
<view id="ajax-test" key="at" mode="ajax-test" inherit="default-mode"> <!-- default layout for normal requests --> <layout main="main"> <include ...> [...] </layout> <!-- layout for the ajax request using the ajaxtest template--> <layout id="ajax" main="ajaxtest"/> </view>
<mode id="ajax-test" inherit="default-mode"> <yahoo-web-command id="defaultSearch" inherit="default-yahoo-web-command" asynchronous="true"/> <yet-another-search-command id="yasc" inherhit="default-yasc"/> </mode>
There's a few different ways AJAX/SESAT can be used to enhance a web page. What's probably most useful is the ability to fetch slow results using a second request.
Note: This is currently broken and probably won't work as expected until SESAT 2.18. See http://sesat.no/scarab/issues/id/SKER4737
The following steps will show a typical use of this:
Another use would be to only fetch the results of specific search commands:
Enable DWR (the dependency and the servlet). This serialises the whole datamodel through the request so it is available in the client's javascript. This is a far more advanced approach when much more logic is required on the client side. DWR is disabled by default in Sesat as we suspect the simpler approach is well, simpler.