You say that you already have a view panel that shows the search results. I'm assuming that you're using the search
attribute on the view panel object to do that. Another assumption is that you're computing the full text query in the search
attribute based on an input field that's bound to a scoped variable (possibly the sessionScope
). So your datasource on the search XPage would look something like this:
<xp:this.data>
<xp:dominoView
var="view1"
viewName="yourSearchView">
<xp:this.search><![CDATA[#{javascript:"[subject]=\"" + sessionScope.searchField + "*\"";}]]></xp:this.search>
</xp:dominoView>
</xp:this.data>
In the Export XPage you can restrict the entries that are exported by applying the same query to the view before exporting the results. To do that you can use the 'FTSearch()' function on the view:
myView.FTSearch("[subject]=\"" + sessionScope.searchField + "*\");
Based on the code on David's cheatsheet I tested this and it turns out that for some reasons if you add this row, the NotesViewNavigator
that is constructed based on the (filtered) view isn't limited to the search results, but still contains all entries. The solution to that is to remove the NotesViewNavigator
object and use a NotesViewEntryCollection
:
var exCon = facesContext.getExternalContext();
var writer = facesContext.getResponseWriter();
var response = exCon.getResponse();
var myView:NotesView = database.getView('vwKlanten');
var query = "[subject]=\"em*\"";
myView.FTSearch(query);
var vec:NotesViewEntryCollection = myView.getAllEntries()
var viewEnt:NotesViewEntry = vec.getFirstEntry();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
writer.write("<table>");
writer.write("<thead><tr>");
writer.write("<td><b>Column1Header</b></td>");
writer.write("<td><b>Column2Header</b></td>");
writer.write("<td><b>Column3Header</b></td>");
writer.write("</tr></thead>");
while (viewEnt != null) {
writer.write("<tr>");
writer.write("<td>" + viewEnt.getColumnValues()[0] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[1] + "</td>");
writer.write("<td>" + viewEnt.getColumnValues()[2] + "</td>");
writer.write("</tr>");
var tmp = vec.getNextEntry(viewEnt);
viewEnt.recycle();
viewEnt = tmp;
}
writer.write("</table>");
writer.endDocument();
(BTW: I added a 'recycle()' call to deal with possible memory errors)