|
Keep On Searching
Listing 1. SearchAction's execute() method passes SearchForm, a subclass of ActionForm, to the SearchFacade to create tight coupling between Struts and the persistence tier. public class SearchAction extends Action{
public ActionForward execute(
ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse
response){
// gets a collection of results from the search
// facade
SearchFacade facade = new SearchFacade();
Collection results = facade().find((
SearchForm)form);
//adds the results to the request object
request.setAttribute("results",results);
// forwards to the results page
return mapping.findForward("results.jsp");
}
}
...
public class SearchFacade{
public Collection find(SearchForm form){
Collection collection = null;
// the type here is a subclass of ActionForm and
// tightly bound to Struts
String keyword = form.getKeyword();
Date startDate = form.getStartDate();
Date endDate = form.getEndDate();
// execute a search on the data source
return collection;
}
}
|