📄 createviewpage.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.util;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import com.jdon.util.Debug;
import com.jdon.model.ModelHandler;
import com.jdon.model.ModelForm;
import com.jdon.model.ModelManager;
import com.jdon.strutsutil.FormBeanUtil;
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.ModuleConfig;
/**
* 提供用于Model创建页面的准备工作
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public class CreateViewPage {
private final static String module = CreateViewPage.class.getName();
private ModelManager modelManager;
public CreateViewPage(ModelManager modelManager) {
this.modelManager = modelManager;
}
/**
* 如果在action配置中,配置了name值,那么直接使用Struts自动生成的ModelForm实例
* 如果只规定了attribute值,那么使用ModelHandler子类initForm的ModelForm实例
* @param actionMapping ActionMapping
* @param actionForm ActionForm
* @param request HttpServletRequest
* @throws Exception
*/
public void doCreate(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
ModuleConfig moduleConfig) throws Exception {
Debug.logVerbose(" enter doCreate... ", module);
ModelForm form = getModelFormFromHandler(actionMapping, actionForm, request);
if (form == null)
if (actionForm != null)
form = (ModelForm) actionForm;
else
form = FormBeanUtil.createModelFormNow(actionMapping, actionForm, request,
moduleConfig);
form.setAction(ModelForm.CREATE_STR);
}
/**
* 为创家页面准备一个ModelForm实例
* @param actionMapping
* @param request
* @return
* @throws java.lang.Exception
*/
private ModelForm getModelFormFromHandler(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request) throws
Exception {
String formName = FormBeanUtil.getFormName(actionMapping);
ModelHandler modelHandler = modelManager.borrowtHandlerObject(formName);
ModelForm form = null;
try {
form = modelHandler.initForm(request);
Debug.logVerbose(" active modelHandler.initForm ", module);
FormBeanUtil.saveActionForm(form, actionMapping, request);
if (modelHandler != null)
modelHandler.customizeForm(form, request);
} catch (Exception ex) {
Debug.logError("please check struts-config.xml or modelHandler.initForm" +
ex, module);
throw new Exception("System error! please call system Admin." + ex);
} finally {
modelManager.returnHandlerObject(modelHandler); //返回modelhandler再用
}
return form;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -