1 15 16 package com.jdon.strutsutil; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.apache.struts.action.ActionErrors; 22 import org.apache.struts.action.ActionForm; 23 import org.apache.struts.action.ActionForward; 24 import org.apache.struts.action.ActionMapping; 25 import org.apache.struts.action.ActionMessage; 26 import org.apache.struts.action.ActionMessages; 27 28 import com.jdon.controller.model.ModelIF; 29 import com.jdon.model.ModelForm; 30 import com.jdon.util.Debug; 31 import com.jdon.util.UtilValidate; 32 33 59 public class ModelViewAction extends ModelBaseAction { 60 61 private final static String module = ModelViewAction.class.getName(); 62 63 64 70 public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) 71 throws Exception { 72 Debug.logVerbose("[JdonFramework]--> enter ModelViewAction process ", module); 73 intContext(this.getServlet().getServletContext()); 74 75 ModelForm modelForm = FormBeanUtil.getModelForm(actionMapping, actionForm, request); 76 77 if ((UtilValidate.isEmpty(modelForm.getAction()) ) || modelForm.getAction().equalsIgnoreCase(ModelForm.CREATE_STR)) { 78 Debug.logVerbose("[JdonFramework]--> enter create process ", module); 79 modelForm.setAction(ModelForm.CREATE_STR); 80 createViewPage.doCreate(actionMapping, modelForm, request); 81 82 } else if (modelForm.getAction().equalsIgnoreCase(ModelForm.EDIT_STR)) { 83 84 Debug.logVerbose("[JdonFramework]--> enter " + ModelForm.EDIT_STR + " process ", module); 85 ModelIF model = editeViewPage.getModelForEdit(actionMapping, modelForm, request); 86 if (model == null) return errorsForward(modelForm.getAction(), actionMapping, request); 88 89 }else{ Debug.logVerbose("[JdonFramework]-->action value not supported, enter create process2 ", module); 91 modelForm.setAction(ModelForm.CREATE_STR); 92 createViewPage.doCreate(actionMapping, modelForm, request); 93 } 94 Debug.logVerbose("[JdonFramework]--> push the jsp that forward name is '" + modelForm.getAction() + "'", module); 95 return actionMapping.findForward(modelForm.getAction()); 96 } 97 98 99 private ActionForward errorsForward(String action, ActionMapping actionMapping, HttpServletRequest request) { 100 ActionMessages errors = new ActionMessages(); 101 ActionMessage error = new ActionMessage("id.notfound"); 102 errors.add(ActionErrors.GLOBAL_MESSAGE, error); 103 saveErrors(request, errors); 104 if (actionMapping.findForward(FormBeanUtil.FORWARD_FAILURE_NAME) != null) 105 return actionMapping.findForward(FormBeanUtil.FORWARD_FAILURE_NAME); 106 else 107 return actionMapping.findForward(action); 108 } 109 110 } 111 | Popular Tags |