【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了CatalogAction.java相关资料,希望对各位网友有所帮助!
package jaoso.guestbook.web.action;
import jaoso.framework.util.MyUtils;
import jaoso.framework.web.action.BaseAction;
import jaoso.guestbook.domain.GbCatalog;
import jaoso.guestbook.domain.Message;
import jaoso.guestbook.service.CatalogService;
import jaoso.news.exception.CatalogExistException;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @author Edgeloner 3710167@qq.com
* @since 2004-7-3
*/
public class CatalogAction extends BaseAction {
//~ Instance fields ========================================================
/** DOCUMENT ME! */
private CatalogService catalogService = (CatalogService) getServiceLocator()
.getService("gbCatalogService");
//~ Methods ================================================================
/**
* get all catalog and message
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward getMessage(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
String id = request.getParameter("id");
GbCatalog catalog;
GbCatalog[] catalogs = catalogService.findAll();
Message[] messages;
Integer msgCount;
if (MyUtils.isBlank(id)) {
catalog = catalogs[0];
} else {
catalog = catalogService.getCatalog(id);
}
//查询关键字
String para = request.getParameter("para");
//查询的目录
String catalogId = request.getParameter("catalogId");
//按什么排列
String orderby = request.getParameter("orderby");
//排列次序
String sort = request.getParameter("sort");
//第几页
String page = request.getParameter("pager.offset");
String[] args = { para, catalog.getId(), orderby, sort, page };
messages = catalogService.getMessages(args);
msgCount = catalogService.getResultCount(args);
// Remove the obsolete form bean
removeAttribute(mapping, request);
request.setAttribute("messages", messages);
request.setAttribute("msgCount", msgCount);
request.setAttribute("catalog", catalog);
request.setAttribute("catalogs", catalogs);
return (mapping.findForward("success"));
}
/**
* DOCUMENT ME!
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward addMessage(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
Message msg = (Message) ((DynaActionForm) form).get("message");
String id = request.getParameter("id");
String parent = request.getParameter("parent");
parent = MyUtils.isBlank(parent) ? null : parent;
msg.setContent(MyUtils.htmlEncode(msg.getContent()));
GbCatalog catalog;
GbCatalog[] catalogs = catalogService.findAll();
Message[] messages;
Integer msgCount;
if (MyUtils.isBlank(id)) {
catalog = catalogs[0];
} else {
catalog = catalogService.getCatalog(id);
}
msg.setCreateDate(new Date());
catalogService.addMessage(catalog.getId(), msg, parent);
catalog = catalogService.getCatalog(catalog.getId());
//查询关键字
String para = request.getParameter("para");
//查询的目录
String catalogId = request.getParameter("catalogId");
//按什么排列
String orderby = request.getParameter("orderby");
//排列次序
String sort = request.getParameter("sort");
//第几页
String page = request.getParameter("pager.offset");
String[] args = { para, catalog.getId(), orderby, sort, page };
messages = catalogService.getMessages(args);
msgCount = catalogService.getResultCount(args);
// Remove the obsolete form bean
removeAttribute(mapping, request);
request.setAttribute("messages", messages);
request.setAttribute("amsgCount", msgCount);
request.setAttribute("catalog", catalog);
request.setAttribute("catalogs", catalogs);
return (mapping.findForward("success"));
}
/**
* create new catalog
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward create(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
ActionErrors errors = new ActionErrors();
GbCatalog catalog = (GbCatalog) ((DynaActionForm) form).get("catalog");
catalog.setId(null);
try {
catalogService.createCatalog(catalog);
} catch (CatalogExistException e) {
errors.add("create error", new ActionError("errors.CatalogExist"));
}
if (!errors.isEmpty()) {
saveErrors(request, errors);
saveToken(request);
return (mapping.getInputForward());
} else {
// Remove the obsolete form bean
removeAttribute(mapping, request);
return (mapping.findForward("success"));
}
}
/**
* load all catalog for edit
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward load4edit(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
// Remove the obsolete form bean
removeAttribute(mapping, request);
request.setAttribute("catalogs", catalogService.findAll());
return (mapping.findForward("success"));
}
/**
* load all catalog for remove
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward load4remove(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
// Remove the obsolete form bean
removeAttribute(mapping, request);
request.setAttribute("catalogs", catalogService.findAll());
return (mapping.findForward("success"));
}
/**
* remove catalog
*
* @param mapping DOCUMENT ME!
* @param form DOCUMENT ME!
* @param request DOCUMENT ME!
* @param response DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
public final ActionForward remove(final ActionMapping mapping,
final ActionForm form, final HttpServletRequest request,
final HttpServletResponse response) {
String id = request.getParameter("catalog.id");
catalogService.removeCatalog(id);
// Remove the obs
上一篇:
Catalog.java
下一篇:
骨科病房开展优质护理服务的措施与体会