Searching in ATG Commerce is handled by one of the components based on the CatalogSearchFormHandler class:

Implementing a search in your pages is quite simple. First, ensure that your JSP includes the search servlet bean. This example uses CatalogSearch, but you can use any of the other servlet beans for more specific searches.

<IMPORTBEAN BEAN="/atg/commerce/catalog/CatalogSearch">

This code is the search input form. The form takes the user’s input and sends it to the CatalogSearch servlet bean for processing.

<dsp:form action="simple_search.jsp" method="POST">
  <table>
    <tr>
      <td>
         <input value='<dsp:valueof
                 bean="/OriginatingRequest.requestLocale.locale"/>'
                 type="hidden"
                 name="repositoryKey">
         <dsp:input bean="CatalogSearch.searchInput" size="30" type="text"/>
         <dsp:input bean="CatalogSearch.search" value="Search" type="submit"/>
      </td>
    </tr>
  </table>
</dsp:form>

To display the search results to your user, use code such as the following example.

<%@ taglib uri="http://www.atg.com/dsp.tld" prefix="dsp" %>
<dsp:page>

<%--
---------------------------------------------------------------
This JSP bean displays the contents of search
that potentially returns both category and product repository items.
The one paramater, ResultArray, accepts a HashMap that contains
elements with the keys "category" and "product".  The values of these
keys are collections of category or product repository items found in
the search.
--------------------------------------------------------------
--%>

<dsp:importbean bean="/atg/dynamo/droplet/Switch"/>
<dsp:importbean bean="/atg/dynamo/droplet/IsEmpty"/>
<dsp:importbean bean="/atg/dynamo/droplet/ForEach"/>
<dsp:importbean bean="/atg/dynamo/droplet/RQLQueryForEach"/>

<dsp:droplet name="ForEach">
  <dsp:param param="ResultArray" name="array"/>

<%--Each item in this array is a Collection of Categories or
          Products...--%>
  <dsp:param value="ResultCollection" name="elementName"/>

  <dsp:oparam name="output">
    <dsp:droplet name="Switch">

<%--The key tells us if this is a Collection of Products
              or Categories:--%>
      <dsp:param param="key" name="value"/>

<%--For the list of CATEGORIES: --%>
      <dsp:oparam name="category">

        <blockquote>

        <dsp:droplet name="Switch">
          <dsp:param param="ResultCollection" name="value"/>
          <dsp:oparam name="default">
            <p>

<%--For each Category in the Collection: --%>
            <dsp:droplet name="ForEach">
              <dsp:param param="ResultCollection" name="array"/>
              <dsp:param value="+displayName" name="sortProperties"/>
              <dsp:param value="Category" name="elementName"/>
              <dsp:oparam name="outputStart">
                <b>We found these categories matching your search</b>
                <p>
              </dsp:oparam>
              <dsp:oparam name="output">


<%-- Display a link to the Category: --%>
                <dsp:getvalueof id="a78" param="Category.template.url"
                                        idtype="java.lang.String">
<dsp:a href="<%=a78%>">
                  <dsp:param param="Category.repositoryId" name="id"/>
                  <dsp:param value="jump" name="navAction"/>
                  <dsp:param param="Category" name="Item"/>
                  <dsp:valueof param="Category.displayName">No
                       name</dsp:valueof></dsp:a></dsp:getvalueof>
                <br>
              </dsp:oparam>
              <dsp:oparam name="empty">
                <b>There are no categories matching your search</b>
                <p>
              </dsp:oparam>
            </dsp:droplet>
          </dsp:oparam>

<%--If NO Categories returned by the search: --%>
          <dsp:oparam name="unset">
            No category items in the catalog could be found that match your query
          </dsp:oparam>
        </dsp:droplet>
<%--ForEach Category--%>

        </blockquote>
        <P>
      </dsp:oparam>

<%--For the list of PRODUCTS: --%>
      <dsp:oparam name="product">
        <blockquote><p>

        <dsp:droplet name="Switch">
          <dsp:param param="ResultCollection" name="value"/>

          <dsp:oparam name="default">


<%--For each Product in the Collection: --%>
            <dsp:droplet name="ForEach">
              <dsp:param param="ResultCollection" name="array"/>
              <dsp:param value="+displayName" name="sortProperties"/>
              <dsp:param value="Product" name="elementName"/>
              <dsp:oparam name="outputStart">
                <p>
                <b>We found these products matching your search</b>
                <p>
              </dsp:oparam>
              <dsp:oparam name="output">

<%-- Display a link to the Product: --%>
                <dsp:getvalueof id="a173" param="Product.template.url"
                            idtype="java.lang.String">
<dsp:a href="<%=a173%>">
                  <dsp:param param="Product.repositoryId" name="id"/>
                  <dsp:param value="jump" name="navAction"/>
                  <dsp:param param="Product" name="Item"/>
                  <dsp:valueof param="Product.displayName">No name</dsp:valueof>
                   &nbsp;-&nbsp;<dsp:valueof param="Product.description"/>
                </dsp:a></dsp:getvalueof>

                <br>
              </dsp:oparam>
              <dsp:oparam name="empty">
                <b>There are no products matching your search</b>
                <p>
              </dsp:oparam>

            </dsp:droplet>
<%--ForEach Product--%>

          </dsp:oparam>


<%--If NO Products returned by the search:--%>
          <dsp:oparam name="unset">
           No product items in the catalog could be found that match your query<p>
          </dsp:oparam>

        </dsp:droplet>
        </blockquote><P>
      </dsp:oparam>
    </dsp:droplet>

  </dsp:oparam>

</dsp:droplet>
<%--ForEach Item returned by Search --%>

</dsp:droplet>

</dsp:page>
 
loading table of contents...