1.1.1 创建项目信息
执行项目信息查询列表显示的文件请求处理顺序如下:
1、 ProjectListSearchAction
2、 projectlist.jsp
3、 ProjectFormLoadAction
4、 projectform.jsp
5、 ProjectFormSaveAction
6、 success.jsp or failed.jsp
7、 ProjectListSearchAction
ProjectFormLoadAction内容如下:
package com.ort.strutsdemo.simpledemo.controller;
/**
* <p>Title: Struts Training </p>
* <p>Description: Struts内部培训Demo</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author Liuz
* @version 1.0
*/
import org.apache.struts.action.*;
import javax.servlet.http.*;
import com.ort.strutsdemo.simpledemo.business.BusinessDelegate;
import com.boss.module.operation.object.Project;
import com.ort.strutsdemo.simpledemo.Constants;
import com.ort.strutsdemo.simpledemo.controller.exception.ExceptionBean;
import com.ort.strutsdemo.simpledemo.ui.ProjectForm;
import com.boss.module.operation.object.searchresult.help.ResultSetIterator;
public class ProjectFormLoadAction
extends Action {
BusinessDelegate businessDelegate = null;
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest request,
HttpServletResponse response) {
businessDelegate = BusinessDelegate.getInstance();
DynaActionForm form = (DynaActionForm)actionForm;
String action = (String)form.get("action");
String projectCode = (String)form.get("projectCode");
try {
Project project = null;
if ( ("create".equals(action))) {
project = new Project();
}
else {
project = businessDelegate.getProject(projectCode);
}
project.setAction(action);
ProjectForm modifyForm = new ProjectForm();
org.apache.commons.beanutils.PropertyUtils.copyProperties(
modifyForm, project);
if (! ("create".equals(action))) {
modifyForm.setSiteCode(project.getSite().getSiteCode());
}
request.setAttribute(Constants.PROJECT_SINGLEFORM_KEY, modifyForm); //为下一个页面,即projectform.jsp的显示提供数据
//装载当前页面所需要显示小区信息
ResultSetIterator siteIterator = businessDelegate.getSitesIterator();
java.util.List sites = siteIterator.getElements(1);
request.getSession().setAttribute(Constants.SITE_LISTFORM_KEY,
sites);
return actionMapping.findForward("success");
}
catch (Exception ex) {
com.ipbs.util.Log.println("[ProjectFormLoadAction.java][Exception]:"+ex.getMessage());
ExceptionBean exception = new ExceptionBean();
exception.setErrorMsg(Constants.getExceptionMsg(ex));
exception.setReturnPath(actionMapping.findForward("failed.return").getPath());
request.setAttribute(Constants.EXCEPTION_BEAN,exception);
return actionMapping.findForward("failed");
}
}
}
projectform.jsp内容如下:
<%
/**
* 文件名:projectform.jsp
* 描述:在执行添加、修改操作之前,需要提供一个form供用户输入数据,在执行删除操作之前,
* 需要提供一个form将被删除数据显示出来,供用户确认。该jsp页面就是用来满足这些需要,
* 提供对单条项目信息的显示,根据具体的操作类型(创建、修改、删除),数据被显示在可编
* 辑的输入控件中或不可编辑的
*
*+------------------------------------------------------------------------------
* 更改历史
* 更改时间 更改人 目标版本 更改内容
*+------------------------------------------------------------------------------
* 2004-04-21 16:09 liuz 1.00.000 创建
*
*
*/
%>
<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title>
<logic:equal value="modify" property="action" name="projectForm">
<bean:message key="project.project_modify"/>
</logic:equal>
<logic:equal value="create" property="action" name="projectForm">
<bean:message key="project.project_create"/>
</logic:equal>
<logic:equal value="delete" property="action" name="projectForm">
<bean:message key="project.project_delete"/>
</logic:equal>
</title>
<link href="css/main.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#ffffff">
<html:form action="/projectformsave" method="post" onsubmit="return validateProjectForm(this);">
<table width="70%" border="0" align="center" cellpadding="3" cellspacing="1" class="tablebodycolor">
<tr class="tdbodycolor">
<td colspan="2" class="tdheadcolor">
<logic:equal value="modify" property="action" name="projectForm">
<bean:message key="project.project_modify"/>
</logic:equal>
<logic:equal value="create" property="action" name="projectForm">
<bean:message key="project.project_create"/>
</logic:equal>
<logic:equal value="delete" property="action" name="projectForm">
<bean:message key="project.project_delete"/>
</logic:equal>
</td>
</tr>
<tr class="tdbodycolor">
<td width="15%"><div align="right"><bean:message key="project.projectcode"/></div></td>
<td width="85%">
<logic:equal value="modify" property="action" name="projectForm">
<html:hidden property="projectCode" write="true"/>
</logic:equal>
<logic:notEqual value="modify" property="action" name="projectForm">
<html:text styleClass="input" maxlength="10" property="projectCode" size="30"/>
</logic:notEqual>
</td>
</tr>
<tr class="tdbodycolor">
<td><div align="right"><bean:message key="project.projectname"/></div></td>
<td><html:text styleClass="input" maxlength="30" property="projectName" size="30"/></td>
</tr>
<tr class="tdbodycolor">
<td><div align="right"><bean:message key="project.discount"/></div></td>
<td><html:text styleClass="input" maxlength="10" property="discount" size="10"/>
%</td>
</tr>
<tr class="tdbodycolor">
<td><div align="right"><bean:message key="project.site"/></div></td>
<td>
<html:select property="siteCode">
<html:options collection="SITES" labelProperty="siteName" property="siteCode"/>
</html:select>
</td>
</tr>
<tr class="tdbodycolor">
<td colspan="2"><div align="center">
<html:hidden property="action" />
<html:submit><bean:message key="button_submit"/></html:submit>
<html:cancel><bean:message key="button_cancel"/>
</html:cancel>
</div></td>
</tr>
</table>
</html:form>
<html:javascript formName="projectForm"
dynamicJavascript="true"
staticJavascript="false"/>
<script language="Javascript1.1" src="staticJavascript.jsp"></script>
</body>
</html>