In this lesson you will create the controller
JSP file for your new search definition. The controller JSP file will
be used to provide the search service, which will be called by the
search definition of the Management Center. The controller JSP file
gets the search terms from the user interface as parameters, and then
invokes the wcf:getData
tag library to retrieve the
Noun that is used for the Management Center object. In the wcf:getData
tag,
the expressionBuilder
parameter defines the query
template to run when performing the search. Expression builders from
the previous lesson are used.
About this task
Each wcfSearchDefinition
has an associated wcfSearchService
.
This service is implemented as a controller JSP file that takes the
search terms as parameters, and then invokes the wcf:getData
tag
library to retrieve the Noun that is used for the Management Center
object. In the wcf:getData
tag, the expressionBuilder
parameter
defines the query template to run when performing the search. The
query template is mapped with the SQL which will be executed in the
database to retrieve the data.
For more information about the
Management Center Web Application, refer to Management
Center Web application.
To complete a search across warranty
columns with different data types, you define different expression
builders according to whether the search text is numeric or not.
Procedure
- Open
WebSphere Commerce Developer.
- In the Enterprise Explorer view,
navigate to
- Right click the catalog folder
and select .
In the File name field, type FindAllCatalogEntriesByWarranty.jsp,
and then click Finish. The new controller
JSP file is created and opened in the default editor.
- Add the following sample code to the JSP file:
<?xml version="1.0" encoding="UTF-8"?>
<%--
===================================================================
Customization
===================================================================
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://commerce.ibm.com/foundation" prefix="wcf"%>
<%
// Do judgment if the input search text is numeric,
//if it is, assign expression builder as "findAllCatentriesByWarrantySearchNumeric";
//if not assign expression builder as "findAllCatentriesByWarrantySearchNonNumeric"
boolean isNumeric = false;
String searchText = request.getParameter("searchText");
if (searchText!=null && !searchText.equals("")){
try {
Integer.valueOf(searchText);
isNumeric = true;
}catch (NumberFormatException ne){
isNumeric = false;
}
}
String expressionBuilder = "";
if (isNumeric){
expressionBuilder = "findAllCatentriesByWarrantySearchNumeric";
}else{
expressionBuilder = "findAllCatentriesByWarrantySearchNonNumeric";
}
%>
<c:choose>
<c:when test="${empty param.searchText}">
<%-- No search criteria is specified --%>
<objects
recordSetCompleteIndicator="true"
recordSetReferenceId=""
recordSetStartNumber=""
recordSetCount="0"
recordSetTotal="0">
</objects>
</c:when>
<c:otherwise>
<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]"
var="catentries"
expressionBuilder="<%=expressionBuilder%>"
varShowVerb="showVerb"
recordSetStartNumber="${param.recordSetStartNumber}"
recordSetReferenceId="${param.recordSetReferenceId}"
maxItems="${param.maxItems}">
<wcf:contextData name="storeId" data="${param.storeId}"/>
<wcf:contextData name="catalogId" data="${param.masterCatalogId}"/>
<wcf:param name="warterm" value="${param.searchText}"/>
<wcf:param name="catEntryTypes" value="ProductBean,BundleBean,PackageBean,DynamicKitBean"/>
<wcf:param name="wartype" value="${param.searchText}"/>
<wcf:param name="careinstruction" value="${param.searchText}"/>
</wcf:getData>
<jsp:directive.include file="../../commerce/catalog/restricted/serialize/SerializeCatalogEntries.jspf"/>
</c:otherwise>
</c:choose>
-
The wcf:getData tag has the following attributes and sub-elements:
- type:
- The data type of the data that is to be retrieved. Here you use
com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType[]
to
retrieve CatalogEntry list.
- expressionBuilder:
- The name of a configured expression builder, which is defined
in the get-data-config.xml file for each component. The Java code
near the start of the page determines whether to use
findAllCatentriesByWarrantySearchNumeric
or findAllCatentriesByWarrantySearchNonNumeric
.
- recordSetStartNumber, recordSetReferenceId, maxItems
- The parameters used to support paging.
- wcf:contextData:
- The sub-tag to retrieve context information. In this example you
are retrieving the
storeId
and catalogId
context
information.
- wcf:param:
- The tag to retrieve parameters value. Four parameters are assigned
in this example:
- warterm, wartype, careinstruction:
- The values for these 3 parameters are the same, which is from
search input field. You assign these parameters here in order to build
your search logic: search all the catalog entries with the warranty
information matched with the input value, the warranty information
include wartype, warterm and careinstruction.
- catEntryTypes
- The catalog entry types to be retrieved. In WebSphere Commerce
Catalog system, there are several catalog entries type, in this search,
you will only retrieve those with the type of Product, Bundle, Package
and DynamicKit.
For a detailed description of the wcf:getData tag,
see Tag:
getData.
Note: When creating new controller JSP files, you can copy
an existing similar controller JSP file and update it with your customization.
For example, for the new controller JSP file in this tutorial, a similar
file is \LOBTools\WebContent\jsp\commerce\catalog\restricted\FindAllCatalogEntriesExceptSKUs.jsp,.
For future projects, you can copy and modify this file to create a
new one.
- Save and close the file.
- Add a new action-mappings configuration to the Struts extension
configuration file, to map the action used in
wcfSearchService
with
this new controller JSP:
- In the Enterprise Explorer view,
navigate to the Struts extension
configuration file already exists, and is named struts-extension.xml.
Double click the file to open it in the default editor.
- In the source view of the struts-extension.xml file,
add the following line to the action-mappings section:
<action path="/FindCatalogEntries-ByWarranty" forward="/jsp/mycompany/catalog/FindAllCatalogEntriesByWarranty.jsp" />
- Save and Close the file.
- Restart the WebSphere Commerce Test Server to load the
new configuration