Filter View for Search Results When Passed Via URL

Mindwatering Incorporated

Author: Tripp W Black

Created: 12/27/2010 at 09:20 PM

 

Category:
Notes Developer Tips
XPages

Overview:
To allow a search box on a header or a search page submission to pass via the URL the search term to a target XPage containing a view and automatically filter the view's content based on the search word or phrase. If nothing is passed on the URL, the view should show everything.

Steps:
1a. Create an Edit Box to be used as the search box with the following properties:
Edit Box tab:
Name: searchText
Data tab:
Bind data using: Advanced
Use: Scoped Variable
- Parameter: View Scope
- Variable name: searchValue
- Default: Search ...

1b. Update the events for the box so that adding text and clicking <enter> key performs the search:
Events tab:
- Client tab:
Add the following code into the Script Editor:
onkeypress:
if (thisEvent.keyCode != '13') {
return false;
}
onkeypress:
var me = document.getElementById("#{id:searchText}");me.value = "";
- Server tab:
-- Simple Action
-- Open Page
-- Add the following code Server Side JavaScript code into the Script Editor:
if(compositeData.searchPage!=null){
return compositeData.searchPage+"?open&searchValue=" + viewScope.searchValue;
}else{
// get target page from resources file
tmppg = '/' + layout.getString("search.searchPage");
print (tmppg);
print (facesContext.getExternalContext().getRequestServletPath());
return (tmppg + '?open&searchValue=' + viewScope.searchValue);
// following code uses current page instead, current page has to be coded for this search string passed
//return facesContext.getExternalContext().getRequestServletPath()+"?open&searchValue=" + viewScope.searchValue;
}

3. In the target XPage with the view, click on the view's view panel object.
e.g. View:viewPanel1

4a. Under the Properties tab, select the All Properties tab on the left.
4b. Open the data twistie (xp:dominoView), click the blue diamond for the search option, and select computed value... .
4c. Add the following JavaScript Server Side code:
context.getUrlParameter("searchValue");


previous page