Datasheet
want to use a validator as a mechanism to check a condition that is more complicated than simply “pre-
sent” or “not present.” If either of these conditions is false, then the
LuceneValidator will throw a
ValidatorException.
Now that we have managed the major logical parts of the
LucenePortlet, we will review the presenta-
tion aspects of the portlet. The following code shows
search_view.jsp, which presents a user interface
for searching:
<%@ page import=”javax.portlet.PortletURL” %>
<%@ taglib uri=”http://java.sun.com/portlet” prefix=”portlet” %>
<portlet:defineObjects/>
<table width=”100%” border=”0” cellspacing=”0” cellpadding=”0”>
<tr>
<th>SEARCH</th>
</tr>
<tr>
<td>
<FORM action=”<portlet:actionURL />” method=”POST”>
<input type=”text” name=”searchString”/>
<INPUT type=”submit” name=”Submit” value=”Go”/>
</FORM>
</td>
</tr>
</table>
In this JSP, we see the first use of the Portlet Tag Library. These tags provide access to the portlet from
within a JSP. The most interesting use here is the
actionURL tag, which is the proper way of creating
links within a portlet application. Creating them as was traditionally done in Web applications, by
appending parameters to an HTTP query string, is not correct, as it may omit portal-specific references
that should be included in the URL.
Logically, we now need a page to view the results of our search. The following code provides a search
results page:
<%@ page import=”java.util.*,org.apache.lucene.search.*,java.text.*” %>
<%@ page import=”org.apache.lucene.document.*” %>
<jsp:useBean id=”hits” scope=”request” type=”org.apache.lucene.search.Hits”/>
<%
String shaded = “silver”;
DecimalFormat form = new DecimalFormat(“#”);
%>
<p>
<i><b><%=hits.length()%></b></i> Documents match your request.
<p>
<center>
<table width=”100%”>
<%
for (int i = 0; i < 25; i++) {
Document doc = hits.doc(i);
if (i % 2 == 0) {
shaded = “silver”;
37
The Java Portlet API (JSR 168)
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 37