Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
150
Chapter 11. Services Tutorials
package com.example.binder;
import com.arsdigita.runtime.CompoundInitializer;
import com.arsdigita.runtime.DomainInitEvent;
import com.arsdigita.search.MetadataProviderRegistry;
public class NoteInitializer extends CompoundInitializer {
public void init(DomainInitEvent evt) {
super.init(evt);
MetadataProviderRegistry.registerAdapter(
Note.BASE_DATA_OBJECT_TYPE,
new NoteMetadataProvider());
}
}
Example 11-15. Registering a provider
11.6.2. Creating a search user interface
This section of the tutorial outlines the steps required to add user interface for performing searches
of content within an application. The
com.arsdigita.search.ui
package contains a library of
components which serve as the building blocks for an application’s search UI. The main files of
interest are:
QueryComponent.java
BaseQueryComponent.java
ResultsPane.java
FilterComponent.java
11.6.2.1. Basic search form
The first step in building a search form is to create a form containing a text entry widget for the query
string. The
QueryComponent
class is a general purpose, abstract Bebop container implementing the
QueryGenerator
interface. This interface provides a mechanism for retrieving a query specification
using the current page state without requiring any knowledge about the structure of the data entry
form (for that matter, there might not be any form at all!).
The
BaseQueryComponent
class is a simple subclass of
QueryComponent
providing a widget for
specifying the query string and APIs for adding filter components (more on these later). This is the
component to start with when creating a search UI for an application. The only pre-requisite is that is
be contained within a Bebop form.
QueryComponent query = new BaseQueryComponent();
Form form = new Form("search");
form.add(m_query):
form.add(new Submit("Search notes"));
add(m_query);
Example 11-16. Creating a basic search form