Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
Chapter 11. Services Tutorials
151
11.6.2.2. Displaying results
The next stage is to add functionality for processing the query specification and displaying the re-
sults. The
ResultsPane
takes care of both of these tasks, only requiring an implementation of the
QueryGenerator
interface be passed into its constructor, which of course is already fulfilled by the
QueryComponent
class.
ResultPane results = new ResultPane(query);
add(results);
Example 11-17. Adding a result pane
11.6.2.3. Filtering results
Since search is a system wide service, the result of the previous stage is a component that searches
every single object type for which there is a search metadata provider registered. For internal appli-
cation search, a filter is required to restrict results to one or more object types. There is a choice of
two classes that can be used for this task, both part of the
com.arsdigita.search.ui.filters
package.
ObjectTypeFilterComponent
a static component that restricts to the list of object types passed
into its constructor.
ObjectTypeFilterWidget
a dynamic widget that presents the list of object types passed into its
constructor in a form, enabling the user to restrict the search.
For the binder application, there is only a single object type, Note, so the
ObjectTypeComponent
is
most appropriate.
FilterComponent objTypeFilter =
new ObjectTypeFilterComponent(Note.BASE_DATA_OBJECT_TYPE));
query.add(objTypeFilter);
Example 11-18. Filtering by object type
11.6.2.4. Note search component
These three stages now all combine to form a
NoteSearchComponent
that can be dropped into pages
in the Binder application (or indeed any other application wishing to
Note
objects.
package com.example.binder.ui;
import com.example.binder.Note;
import com.arsdigita.search.ui.BaseQueryComponent;
import com.arsdigita.search.ui.QueryComponent;
import com.arsdigita.search.ui.ResultPane;
import com.arsdigita.search.ui.FilterComponent;
import com.arsdigita.search.ui.ObjectTypeFilterComponent;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.form.Submit;
public class NoteSearhComponent extends SimpleContainer {