Since subsequent requests differ only in the requested page of results, it is most efficient just to retrieve the most recent search request, change the value of the goToPage
property, and resubmit the request. There are two ways to do this:
Modify properties on the form, and resubmit it. This avoids the memory use required to save the request in the
SearchSession
. The downside is that resubmitting the form is difficult if you are creating your links through anchor tags. In that case, it is generally easiest to write a JavaScript function that makes the necessary changes and submits the form.Save the request in the
SearchSession
. This allows you to retrieve the request, modify it, and reissue it; no JavaScript is necessary. The downside is that this approach can use a lot of memory, especially if there are many users at your site issuing search queries.
Note that resubmitting a modified request is useful for faceted search as well as for paging.
Example of Resubmitting the Form
If you do not want to save the request in the SearchSession
, you will need to resubmit the form. Create a JavaScript function like this:
function nextPage(pageNum, requestChainToken) { document.searchForm.requestChainToken.value = requestChainToken; document.searchForm.goToPage.value = pageNum; document.searchForm.submit(); return false; }
You can then invoke the function when the user clicks on a link for a specific page:
<a href="#" onclick="return nextPage('<%=pageValue.toString()%>', '${formHandler.searchResponse.requestChainToken}');"> <dsp:valueof param="count"/> </a>
When the link is clicked, the page number associated with the link and the requestChainToken
of the current search response are passed to the function. The function uses these values to set the goToPage
property and the requestChainToken
property of the form, which it then submits. In addition to specifying the results page to display, this ensures that the same requestChainToken
value is associated with each subsequent search request.
Example of Saving the Request in the SearchSession
If you save the request in the SearchSession
, you can avoid the use of JavaScript. Instead, when a user clicks on a link for a page, you set the necessary properties (including the saveRequest
property) on the saved request through dsp:property
tags, and then resubmit the request:
<dsp:a href="queryExampleFastSave.jsp#Paging"> <dsp:valueof param="count"/> <dsp:property bean="QueryFormHandler.goToPage" paramvalue="count" name="fh_gtp" priority="29"/> <dsp:property bean="QueryFormHandler.searchRequest.saveRequest" value="true" name="fh_sr" priority="30"/> <dsp:property bean="QueryFormHandler.searchRequest.requestChainToken" value="${formHandler.searchResponse.requestChainToken}" name="fh_rct" priority="30"/> </dsp:a>