Web Server includes a set of JSP tags that can be used to customize the search query and search results pages in the search interface. This section describes the tags and how they are used.
The search tag library is packaged into the install_dir/lib/webserv-rt.jar file, which is always on the server classpath. The sun-web-search.tld tag description file can be found in the install_dir/lib/tlds directory, you can copy this file into the WEB-INF directory of your web application.
The search tags are as follows:
The Web Server search feature is compliant for internalization, and supports multiple character encoding schemes in the same collection. Custom JSPs that expose search can be in any encoding.
This tag constructs an HTML form that contains default, hidden form elements such as the current search result index and number of records per page by default. The default names for the form, index, and number of records are searchform, si, and ns.
The searchForm tag uses the following attributes:
Name- Specifies the name of the form. The default is searchform. The name of a form is the identifier for all other tags.
Action (Optional) - Specifies the form action.
Method (Optional) - Specifies the method of submission, GET or POST. The default is GET.
elemStart (Optional) - Specifies the name of the hidden Start element. If not specified, the default si will be used.
Start (Optional) - An integer indicating the starting index for displaying the search result. The default is 1.
elemNumShown (Optional) - The name of the nShown element. If not specified, the default ns is used.
numShown. (Optional) - An integer indicating the number of results to be shown per page. The value of the attribute will be retrieved by requesting parameter elemNumShown. The default is 10.
<s1ws:form action="results.jsp" /> ... </s1ws:searchForm>
This example creates an HTML form tag <form name="searchform" action="results.jsp" method="GET">, along with two hidden input boxes:
A hidden input box for starting the index named si with a value from the si parameter or default 1
A hidden input box for the number of records per page named ns with a value from the ns parameter or default 20
This tag creates a hidden inputbox or select box, or multiple checkboxes, depending on the attribute input. If only one collection exists, the tag will create a hidden inputbox by default.
The CollElem tag uses the following attributes:
Name- Specifies the name of the form element created. The default is c.
Items (Optional) - A comma-delimited string representing search collections available. The tag retrieves all collections available on the server if the attribute is empty.
Type (Optional) - The type of form element used for displaying collections. Valid options are hidden, select, and checkbox. The default value is hidden if one collection exists, and checkbox if there are multiple collections.
Rows (Optional) - Represents size if the type is select, or the number of rows. The default behavior is to satisfy the Cols attribute first. That is, the collections will be listed in columns as specified by the Cols attribute.
Cols - Represents number of columns and is only required if type is checkbox. If Cols and Rows are not specified, the collections will be listed horizontally.
Defaults - Specifies a comma-delimited string containing 1s or 0s indicating the selection status of the search collections. An item is selected if the setting is 1, and not selected if the setting is 0. If there is a form action exists , these values will be retrieved from the form elements.
cssClass (Optional) - The class name used in every HTML tag created in this tag. This attribute is particularly useful when the type is checkbox, since an HTML table is used for the layout. See the sample code for details.
<s1ws:collElem type="checkbox" cols="2" values="1,0,1,0" cssClass="body" />
This example creates checkboxes in 2 columns with a default name c with the first and third items selected. Fonts and any other HTML styles are defined in the css class body, which includes tr.body, td.body, and input.body.
This tag retrieves the name of the search collections on the server, iterates through them , and passes each of them to the collectionitem tag. Use this tag with collection item tags write your own HTML search collections.
Optional - A comma-delimited string representing the search collections available. The tag retrieves all collections available on the server if the attribute is empty.
<table border=0> <s1ws:collection> <tr><td><input type=checkbox name="c" value="<s1ws:collItem property="name" />"> <s1ws:collItem property="display name" / ></td></tr> </s1ws:collection> </table>
The above code will display all collections with checkboxes.
<select name=elementname> <s1ws:collection> <option value="<s1ws:collItem property="name" />"> <s1ws:colleItem property="display name" /> </s1ws:collection> </select>
This function iterates through the available collections and passes each item to the collection item tag, which in turn displays the name and display name of the item.
This tag displays the name and label of one collection item. This tag must be used inside the collection tag.
Property - Specifies a keyword indicating which property the tag should output. Valid inputs include name, display name, and description. Default is name.
<select name=elementname> <s1ws:collection> <option value="<s1ws:collItem property="name" />"> <s1ws:collItem property="display name" /> </s1ws:collection> </select>
This function iterates through the available collections and passes each item to the collection item tag, which in turn displays the name and display name of the item.
This tag creates an input box.
The queryBox tag uses the following attributes:
name. (Optional) The name of the inputbox. The default is qt.
default. (Optional) The default value for the query box. If the form is submitted, its value will be set using this setting.
size. (Optional) The size of the inputbox. The default is 50.
maxlength. (Optional) The maxlength of the inputbox. The default is 50.
cssClass. (Optional) The CSS class.
<s1ws:queryBox size="30"/>
This example creates an inputbox with default name qt and size=30.
This tag creates a submit button.
The submitButton tag uses the following attributes:
name. (Optional) The name of the button. The default is sb.
default. (Optional) The default value of the button, which will be search.
cssClass. (Optional) The CSS class name.
style. The CSS style.
image. The optional image for the button.
<s1ws:submitButton cssClass="navBar" style="padding: 0px; margin: 0px; width: 50px">
This example creates a submit button with default name sb.
This tag performs the following sections:
This tag handles form action.
It retrieves all elements on the search form.
Validates that there is at least one collection is selected and the query is not empty, and passes the values on to search and results tags as parents or through the page context.
The formAction tag uses the following attributes:
formId. Specifies the name of the form. If not specified, the default form searchForm will be used.
ElemColl. (Optional) The name of the Collection element. The default name c is used.
elemQuery. (Optional) The name of the Start element. The default name qt is used.
elemStart. (Optional) The name of the Start element. The default name si is used.
elemNumShown. (Optional) The name of the numShown element. The default name ns is used.
<s1ws:formAction />
This tag tests whether the form submission is successful.
The formsubmission tag uses the following attributes:
formId. Specifies the name of the form in question. This name must the name assigned with <formAction>.
success. Indicates if the form submission is successful. The values true or yes represents successful action. All other inputs are rendered as failure.
<s1ws:formSubmission success="true" > <s1ws:search> ... </s1ws:formSubmission>
This tag prints out an error message from formAction, if any.
The formActionMsg tag uses the following attributes:
formId. (Optional) Specifies the name of the form in question. If not specified, the default ID is searchForm.
elem. (optional) Specifies the name of the element. Valid inputs are query and collection. When specified, the tag returns an error message, if any, regarding the element. Otherwise, all of the error messages generated are printed out.
<FormActionMsg elem="query">
This tag displays the message query text not specified if a query is not submitted.
The message is printed from the form action where the tag is placed.
This tag executes a search query and returns search results. The search tag retrieves a query string and collections from either a form parent tag or the query and collection attributes. The search results are saved in the page context with a page or session scope.
The search tag uses the following attributes:
formId. Specifies the name of the form used for the search. The default form is used if the attribute is left empty. If this tag is used without a form, this attribute must be set to provide an identifier for the resultIterate tag.
collection. (Optional) A comma-delimited string representing collections used for a search. If form action exists, this attribute is ignored and the values are retrieved by requesting the collection element.
query. (Optional) Specifies the query text. If not provided, the text is retrieved from the query element.
scope. Specifies an integer indicating the scope of the search results. The value 1, which is the default, indicates page scope. 2 indicates session scope.
<s1ws:search />
This search tag uses the default parameters and executes a search. The search results are saved in pageContext with a page scope.
<s1ws:search Collection="col1, col2" Query="Java Web Service" scope="2" />
This search tag executes a search in col1 and col2 using "Java Web Service" as the query string. The search results are saved in pageContext with a session scope.
This tag retrieves the search results from either the parent search tag or the page context. The tag iterates through the results and passing the searchitems to the item tags.
The resultIteration tag uses the following attributes:
formId. Specifies the name of the form associated with the search results. The default form is used if the attribute is left empty. If this tag is used without a form, this attribute must be set as a reference to the search tag.
start. Specifies an integer representing the starting position in the search results. The default is 0. The value is retrieved from the parent formAction tag or pageContext, or the parameter value.
numShown. Specifies an integer indicating the number of results to be shown in one page. The default is 20. The value is retrieved from the parent formAction tag or pageContext.
This tag retrieves a searchitem from the Results parent tag and outputs its properties as specified by the property attribute.
Property. Specifies a case-sensitive string representing field names in a search item, such as title, number, score, filename, URL, size, and date.
This tag returns numbers indicating number of records returned and the range currently displayed.
The resultStat tag uses the following attributes:
formId. Specifies the name of the form associated. The default form is used if the attribute is left empty. If this tag is used without a form, this attribute must be set as a reference to the search tag.
type. Specifies the type of statistics data. Valid inputs are start, end, range (for example, 1-20), and total.
This tag creates a navigation bar.
The resultNav tag uses the following attributes:
formId. Specifies the name of the form associated with the navigation bar. The default form is used if the attribute is left empty. If this tag is used without a form, this attribute must be set as a reference to the search tag.
type. Specifies the type of navigation bar. Valid values are full, previous, and next. A full navigation bar appears as follows : previous 1 2 3 4 5 6 7 8 9 10 next, where 5 is currently selected. The number of page number links is determined by the offset attribute and the number of pages available.
caption. Only necessary if the type is previous or next and the default text is not needed. caption can be any HTML file.
offset. Specifies the number of page links around the selected page. For example, if offset=2, the navigation bar would appear as follows: previous 3 4 5 6 7 next. Only required for type "full."