6.2 Search functionality

 < Day Day Up > 



6.2 Search functionality

To add search functionality to your portlet you will rely on Domino's excellent full text search capability. To use this capability, you need to first have a full text index of the Customers database. We assume you have enabled full text index in the Domino database used in this example.

First, let's analyze the life cycle of the portlet. It will support the actions identified in Table 6-1.

Table 6-1: Actions supported by the Customer List portlet with search

Action name

Description

search

This action responds when a user inserts a search string and clicks the button. The actionPerformed() method inserts the search string and adds it to the Session object. When rendering is being performed by the JSP, it checks to find out if the parameter is in Session and introduces an ftsearch attribute to the <Domino:view> custom tag. And it presents the view filtered.

reset

This action responds when a search statement filtering the view is present and the reset button is pressed. On the actionPerformed() method it removes the search string attribute from the Session, so that when it renders it again, there will be no filter present.

Use the following steps to add search functionality:

  1. Open the WebSphere Studio Application Developer and open the CustomerJSPProject created on the previous chapter.

    We focus on 2 components: the CustomerList.java portlet class and the /jsp/CustomerList/View.jsp file.

  2. Open the CustomerList.java portlet class.

  3. Insert the following action URIs in the doView() method:

     PortletURI searchURI = response.createURI(); DefaultPortletAction searchAction = new DefaultPortletAction("search"); searchURI.addAction(searchAction); request.setAttribute("search", searchURI.toString()); PortletURI resetURI = response.createURI(); DefaultPortletAction resetAction = new DefaultPortletAction("reset"); resetURI.addAction(resetAction); request.setAttribute("reset", resetURI.toString()); 

  4. Implement an ActionListener interface.

  5. Add an empty actionPerformed() method.

  6. Include in the actionPerformed() method the following logic to handle each event:

     public void actionPerformed(ActionEvent event) throws PortletException {    DefaultPortletAction action=(DefaultPortletAction)event.getAction();    PortletRequest request=event.getRequest();    if(action!=null){       if(action.getName().equals("search")) {          request.getPortletSession().setAttribute(             "search",request.getParameter("search"));       }       if(action.getName().equals("reset")) {          request.getPortletSession().removeAttribute("search");       }    } } 

    This code will create the new attribute when the search event is called and remove it when the reset event is called.

  7. Open the /jsp/CustomerList/View.jsp file.

  8. Include the following code just below the Customer List label of the portlet:

     <% String tempSearchString=null;    if(request.getSession().getAttribute("search") != null){    tempSearchString = "FIELD CustomerName contains "       +request.getSession().getAttribute("search"); %>    Currently searching by: <b>       <%=request.getSession().getAttribute("search")%></b>    <INPUT type="button" name="reset" value="Reset search"       onClick="window.location.href='       <%=(String)request.getAttribute("reset")%>'">    <br> <% } else { %>    <form name="<portletAPI:encodeNamespace value="search"/>"          action='<%=(String)request.getAttribute("search")%>'          method="post">       Search: <INPUT type="text" name="search" value="">       <input type="submit" name="Search" value="Go !">    </form> <% }%> 

    This scriptlet, based on the search attribute stored on the session, creates either a form to perform the search (if there is no attribute) or a button to reset the search and display the query.

  9. To filter the Domino view add an attribute on the <Domino:view> tag with the name ftsearch. The tag should be like the following:

     <Domino:view viewname="CustomersByName" dbserver="<servername example:CN=itsotest-dom/O=itsoportal>" dbname="<database name example :apps/customer.nsf>" user="*webuser" host="itsotest-dom" ftsearch="<%=tempSearchString%>"> 

The portlet after you have enabled the search mechanism should look similar to Figure 6-2.

click to expand
Figure 6-2: Customer List portlet with search capabilities



 < Day Day Up > 



Portalizing Domino Applications for Websphere Portal
Portalizing Domino Applications for Websphere Portal
ISBN: 0738499811
EAN: 2147483647
Year: 2003
Pages: 103
Authors: IBM Redbooks

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net