📄 basesearchaction.java
字号:
/*
* Created on 2005/11/2
*/
package com.leeman.wkexs.web.base;
import java.util.Map;
import java.util.HashMap;
import java.util.Enumeration;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.leeman.common.web.ui.CachedPager;
import com.leeman.common.web.ui.ScreenMessageHelper;
import com.leeman.common.web.ui.ScreenMessage;
import com.leeman.wkexs.common.security.WebGuard;
import com.leeman.wkexs.master.users.entity.UsersVO;
/**
* @author Dennis
*/
public abstract class BaseSearchAction extends BaseAction{
public Map getCmdMethodMap()
{
HashMap map = new HashMap();
map.put("init","init");
map.put("search", "search");
map.put("addNew", "addNew");
map.put("selectRecord", "selectRecord");
map.put("newSearch", "newSearch");
map.put("returnToSearch", "returnToSearch");
map.put("nextPage", "nextPage");
map.put("prevPage", "prevPage");
return map;
}
public ActionForward init(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache cache = this.getCollectionCache(request);
if (cache != null)
{
ObjectTokenController otc = new ObjectTokenController(getClientInfo(request),cache);
otc.releaseToken();
otc = null;
}
doInit(mapping, form, request, response);
UsersVO usersVO = new UsersVO();
usersVO.setCompany_id(this.getCompanyId(request));
usersVO.setUser_id(this.getClientInfo(request).getUser_id());
cache = this.getCollectionCache(request);
cache.setPrivList(WebGuard.getUserPrivList(usersVO, cache.getProgram_id()));
if (cache.getPrivList().size() == 0)
{
return mapping.findForward("notAuthorized");
}
else
{
setMode(form, request, BaseConstants.MODE_INIT);
return mapping.findForward(getInitForward());
}
}
public ActionForward newSearch(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
collectionCache.setSearchKey(null);
collectionCache.setSearchResults(new ArrayList());
collectionCache.setSearchPager(new CachedPager());
form.reset(mapping, request);
doNewSearch(mapping, form, request, response);
initSearchForm(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_NEW_SEARCH);
return mapping.findForward(getNewSearchForward());
}
public ActionForward selectRecord(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
CachedPager pager = collectionCache.getSearchPager();
BaseSearchForm baseSearchForm = (BaseSearchForm)form;
collectionCache.setCurrentRecordKey(collectionCache.getSearchResults().get(Integer.parseInt(request.getParameter("selectedIndex")) + pager.getCacheOffset()));
doSelectRecord(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_SELECT_RECORD);
return mapping.findForward(getSelectRecordForward());
}
public ActionForward addNew(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
doAddNew(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_ADD_NEW);
return mapping.findForward(getAddNewForward());
}
public ActionForward returnToSearch(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
form.reset(mapping, request);
if (collectionCache.getSearchKey() != null){
loadFormFromCache(mapping, form, request, response);
}
if (collectionCache.getSearchResults().size() > 0){
doSearch(mapping, form, request, response);
CachedPager pager = collectionCache.getSearchPager();
((BaseSearchForm)form).setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
request.setAttribute("searchPager", pager);
initSearchForm(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_SEARCH);
return mapping.findForward(getSearchForward());
}
else{
return newSearch(mapping, form, request, response);
}
}
public abstract void loadFormFromCache(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception;
public ActionForward search(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
updateCollectionCache(request, form);
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
collectionCache.setSearchResults(new ArrayList());
CachedPager pager = new CachedPager();
collectionCache.setSearchPager(pager);
if (validate(request)){
doSearch(mapping, form, request, response);
if (collectionCache.getSearchResults().size() == 0){
ScreenMessageHelper.addMessage(request, ScreenMessage.WARNING, this.getResourceMessage(request, "message.noRecordFound"), false, true);
}
else{
BaseSearchForm baseSearchForm = (BaseSearchForm)form;
baseSearchForm.setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
request.setAttribute("searchPager", pager);
}
}
initSearchForm(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_SEARCH);
return mapping.findForward(getSearchForward());
}
public boolean validate(HttpServletRequest req) throws Exception
{
return true;
}
public ActionForward prevPage(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
BaseSearchForm searchForm = (BaseSearchForm) form;
CachedPager pager = collectionCache.getSearchPager();
if (pager.isPrevPageCached())
{
pager.setPageRecordStart(pager.getPrevPageStart());
searchForm.setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
}
else
{
pager.setPageRecordStart(pager.getPrevPageStart());
doSearch(mapping, form, request, response);
((BaseSearchForm)form).setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
}
request.setAttribute("searchPager", pager);
initSearchForm(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_SEARCH);
return mapping.findForward(getSearchForward());
}
public ActionForward nextPage(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
BaseSearchForm searchForm = (BaseSearchForm) form;
CachedPager pager = collectionCache.getSearchPager();
if (pager.isNextPageCached())
{
pager.setPageRecordStart(pager.getNextPageStart());
searchForm.setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
}
else
{
pager.setPageRecordStart(pager.getNextPageStart());
doSearch(mapping, form, request, response);
if (collectionCache.getPagedSearchResult(pager.getCacheOffset(),pager.getPageRecordSize()).size() == 0){
pager.setPageRecordStart(pager.getPrevPageStart());
doSearch(mapping, form, request, response);
ScreenMessageHelper.addMessage(request, ScreenMessage.WARNING, this.getResourceMessage(request, "message.noMoreSearchResult"), false, true);
}
((BaseSearchForm)form).setSearchResults(collectionCache.getPagedSearchResult(pager.getCacheOffset(), pager.getPageRecordSize()));
}
request.setAttribute("searchPager", pager);
initSearchForm(mapping, form, request, response);
setMode(form, request, BaseConstants.MODE_SEARCH);
return mapping.findForward(getSearchForward());
}
//Action Forwards
public String getInitForward(){
return "init";
}
public String getAddNewForward(){
return "addNew";
}
public String getNewSearchForward(){
return "search";
}
public String getSearchForward(){
return "search";
}
public String getSelectRecordForward(){
return "selectRecord";
}
public void doAddNew(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{};
public void doNewSearch(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{};
public void initSearchForm(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception
{};
//Abstract Do Functions to be implement
public abstract void doInit(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception;
public abstract void doSearch(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception;
public void doSelectRecord(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{};
protected abstract void updateCollectionCache(HttpServletRequest request, ActionForm form) throws Exception;
protected void doAfterExecute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
super.doAfterExecute(mapping, form, request, response);
BaseCollectionCache collectionCache = (BaseCollectionCache)this.getCollectionCache(request);
if (collectionCache != null){
setPrivList(request, collectionCache.getPrivList());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -