01: package ca.nexcel.books.actions;
02:
03: import java.io.IOException;
04:
05: import javax.servlet.ServletException;
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletResponse;
08:
09: import org.apache.struts.action.Action;
10: import org.apache.struts.action.ActionError;
11: import org.apache.struts.action.ActionErrors;
12: import org.apache.struts.action.ActionForm;
13: import org.apache.struts.action.ActionForward;
14: import org.apache.struts.action.ActionMapping;
15: import org.apache.struts.action.DynaActionForm;
16: import org.huihoo.jfox.soaf.container.ServiceFactory;
17:
18: import ca.nexcel.books.beans.Book;
19: import ca.nexcel.books.business.BookService;
20:
21: public class SearchSubmit extends Action {
22:
23: private ServiceFactory sf = ServiceFactory.getInstance();
24:
25: public ActionForward execute(ActionMapping mapping,
26: ActionForm form, HttpServletRequest request,
27: HttpServletResponse response) throws IOException,
28: ServletException {
29:
30: DynaActionForm searchForm = (DynaActionForm) form;
31: String isbn = (String) searchForm.get("isbn");
32:
33: BookService bookService = (BookService) sf
34: .getService(BookService.class);
35: Book book = bookService.read(isbn.trim());
36:
37: if (null == book) {
38: ActionErrors errors = new ActionErrors();
39: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
40: "message.notfound"));
41: saveErrors(request, errors);
42: return mapping.findForward("failure");
43: }
44:
45: request.setAttribute("book", book);
46: return mapping.findForward("success");
47: }
48: }
|