📄 createviewpageutil.java
字号:
/**
* Copyright 2003-2006 the original author or authors.
* 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 javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionMapping;
import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.ModelIF;
import com.jdon.model.ModelForm;
import com.jdon.model.ModelHandler;
import com.jdon.model.ModelManager;
import com.jdon.strutsutil.FormBeanUtil;
import com.jdon.util.Debug;
/**
* prepare for push a a create/insert view page, we need do some ready works.
*
*
* @author banq
*/
public class CreateViewPageUtil {
private final static String module = CreateViewPageUtil.class.getName();
private ModelManager modelManager;
public CreateViewPageUtil(ModelManager modelManager) {
this.modelManager = modelManager;
}
/**
* create a ModelForm object
*
* two things: 1. create a ModelForm null instance 2. initial ModelForm
* instance value, obtain a inital Model instance copy the Model instance to
* the ModelForm instance
*
* obtaining datas two ways: 1.call ModelHandler initForm method; 2.call
* Modelhandler initModel method;
*
*/
public void doCreate(ActionMapping actionMapping, ModelForm modelForm, HttpServletRequest request) throws Exception {
Debug.logVerbose("[JdonFramework] enter doCreate... ", module);
String formName = FormBeanUtil.getFormName(actionMapping);
ModelHandler modelHandler = modelManager.borrowtHandlerObject(formName);
try {
ModelForm form = modelHandler.initForm(request);
if (form != null) {
form.setAction(ModelForm.CREATE_STR);
FormBeanUtil.saveActionForm(form, actionMapping, request);
} else {
form = modelForm;
}
Debug.logVerbose("[JdonFramework] got a ModelForm ... " , module);
ModelIF modelDTO = modelManager.getModelObject(formName);
modelHandler.formCopyToModelIF(form, modelDTO);
EventModel em = new EventModel();
em.setActionName(form.getAction());
em.setModelIF(modelDTO);
modelDTO = initModel(em, request, modelHandler, form);
//copy initial model to form , intial form;
if (modelDTO != null) { // the model can be null
Debug.logVerbose("[JdonFramework] got a Model From the 'initModel' method of the service", module);
modelHandler.modelIFCopyToForm(modelDTO, form);
}
} catch (Exception ex) {
Debug.logError("[JdonFramework]please check your service 、 model or form, error is: " + ex, module);
throw new Exception("System error! please call system admin. " + ex);
} finally {
modelManager.returnHandlerObject(modelHandler); //返回modelhandler再用
}
}
private ModelIF initModel(EventModel em, HttpServletRequest request, ModelHandler modelHandler, ModelForm form) throws Exception {
ModelIF model = null;
try {
model = modelHandler.initModelIF(em, form, request);
} catch (Exception ex) {
Debug.logError("[JdonFramework] the method 'initForm' of your handler or 'initMethod' of your service happened error: " + ex, module);
throw new Exception(ex);
}
return model;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -