Datasheet
* know it came from a form.
*/
if (aReq.getParameter(“Submit”) != null) {
PortletPreferences prefs = aReq.getPreferences();
String indexPath = aReq.getParameter(“indexPath”);
prefs.setValue(“indexPath”, indexPath);
try {
prefs.store();
aRes.setRenderParameter(
“success”,
“The update was successful.”);
} catch (ValidatorException ve) {
System.out.println(“Preferences did not validate.”);
aRes.setRenderParameter(
“success”,
“The preferences did not validate.”);
}
aRes.setRenderParameter(
“index”,
prefs.getValue(“indexPath”, “”));
/**
* Otherwise, we want to pull the preference, and pass it
* as a render parameter to our portlet.
*/
} else {
PortletPreferences prefs = aReq.getPreferences();
aRes.setRenderParameter(
“index”,
prefs.getValue(“indexPath”, “”));
}
}
}
}
In EDIT mode, we set the “index” portlet preference based on the parameters submitted from the
searchEdit.jsp. If there is no “Submit” parameter, we know that it is the initial view of the EDIT
page, and therefore, we want to retrieve the “index” preference.
The
LucenePortlet uses a common method of building portlets in that it delegates its user interface
rendering to JSPs through a
PortletRequestDispatcher. Two major actions are processed by the
portlet. One, in
VIEW mode, handles searching the Lucene index; and the other, in EDIT mode, allows
modification of the Lucene index location, through a portlet preference called
indexPath.
We want to determine whether the
indexPath preference is actually pointed at a Lucene index, so we
will implement our own
PreferencesValidator, called LuceneValidator, which is shown in the
following code:
/*
* This class demonstrates a basic validator.
*
*/
35
The Java Portlet API (JSR 168)
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 35