📄 modeldispaction.java
字号:
/**
* Copyright 2005 Jdon.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jdon.strutsutil;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jdon.util.Debug;
import com.jdon.controller.model.Model;
import com.jdon.model.ModelHandler;
import com.jdon.model.ModelKey;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.util.RequestUtils;
import com.jdon.strutsutil.util.CreateViewPage;
import com.jdon.model.ModelManager;
import com.jdon.strutsutil.util.EditeViewPage;
import com.jdon.model.ModelManagerRegistry;
import javax.servlet.ServletContext;
import com.jdon.controller.ContainerClient;
/**
* 专门显示Model类。
*
* 为安全起见,单独设立一个类。同时加入缓存机制。
* request的nocache参数表示失效缓存机制。
* modelDispAction.do?nocache
*
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public class ModelDispAction extends ModelViewAction {
private final static String module = ModelDispAction.class.getName();
private ContainerClient containerClient = new ContainerClient();
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
if (modelManager == null) {
ServletContext sc = this.getServlet().getServletContext();
modelManager = (ModelManager) containerClient.getPOJOService(
ModelManagerRegistry.MM_NAME, sc);
createViewPage = new CreateViewPage(modelManager);
editeViewPage = new EditeViewPage(modelManager);
}
ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request,
getServlet().getServletContext());
Model model = this.editeViewPage.getModelForEdit(actionMapping, actionForm,
request, moduleConfig);
if (model == null) { //如果查询失败,显示出错信息
ActionErrors errors = new ActionErrors();
Debug.logError("id.notfound in database", module);
ActionError error = new ActionError("id.notfound");
errors.add(ActionErrors.GLOBAL_ERROR, error);
saveErrors(request, errors);
return actionMapping.findForward(FormBeanUtil.FORWARD_FAILURE_NAME);
} else {
return actionMapping.findForward(FormBeanUtil.FORWARD_SUCCESS_NAME);
}
}
/**
* 首先查询缓存,然后从后台获取已经存在的Model数据
* @param actionMapping
* @param request
* @param modelHandler
* @return
* @throws java.lang.Exception
*/
private Model fetchModel(ActionMapping actionMapping,
HttpServletRequest request,
ModelHandler modelHandler) throws Exception {
String paramKeyValue = this.editeViewPage.getParamKeyValue(actionMapping,
request, modelHandler);
if (paramKeyValue == null) {
Debug.logVerbose(
" the keyValue is null, please finish it in findModelByKey method",
module);
}
String nocache = request.getParameter("nocache");
String formName = actionMapping.getAttribute();
Model model = null;
if (nocache != null) {
model = modelHandler.findModelByKey(paramKeyValue, request);
} else {
//特别是 先从缓存获得。
ModelKey modelKey = new ModelKey(paramKeyValue, formName);
model = modelManager.getCache(modelKey);
if (model == null) {
model = modelHandler.findModelByKey(paramKeyValue, request);
if ( (model != null) && (model.isCacheble())) {
modelManager.addCache(modelKey, model);
}
}
}
return model;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -