fileform.jsp

来自「Java的框架」· JSP 代码 · 共 174 行

JSP
174
字号
<%@ include file="/common/taglibs.jsp"%>

<c:set var="datetimeformat"><fmt:message key="datetime.format"/></c:set>
<c:if test="${param.method == 'add'}">
		<c:set var="title"><fmt:message key="addFile.title"/></c:set>
	  <c:set var="heading"><fmt:message key="addFile.heading"/></c:set>
	  <c:set var="message"><fmt:message key="addFile.message"/></c:set>
</c:if>
<c:if test="${param.method == 'edit'}">
	<c:set var="title"><fmt:message key="editFile.title"/></c:set>
	  <c:set var="heading"><fmt:message key="editFile.heading"/></c:set>
	  <c:set var="message"><fmt:message key="editFile.message"/></c:set>
</c:if>

<html>
	<head>
		<title><c:out value="${title}"/></title>
		<content tag="heading">
			<c:out value="${heading}"/>
		</content>
    <script type="text/javascript" src="<c:url value='/scripts/selectbox.js'/>"></script>
	</head>

	<body>
		<span id="message"><c:out value="${message}"/></span>
		<div class="separator"></div>
		<spring:bind path="fileObject.*">
		    <c:if test="${not empty status.errorMessages}">
		    <div class="error">	
		        <c:forEach var="error" items="${status.errorMessages}">
		            <img src="<c:url value="/images/iconWarning.gif"/>"
		                alt="<fmt:message key="icon.warning"/>" class="icon" />
		            <c:out value="${error}" escapeXml="false"/><br />
		        </c:forEach>
		    </div>
		    </c:if>
		</spring:bind>
		<c:set var="pageButtons">
			<tr>
				<td width="15%">
				</td>
				<td class="buttonBar" width="85%">
					<c:if test="${param.method == 'add'}">
			      <input type="submit" class="button" name="save" onclick="bCancel=false" value="<fmt:message key="button.add"/>" />		
		   			<input type="submit" class="button" name="cancel" onclick="bCancel=true" value="<fmt:message key="button.cancel"/>" />
 			    </c:if>
					<c:if test="${param.method == 'edit'}">
			      <input type="submit" class="button" name="save" onclick="bCancel=false" value="<fmt:message key="button.save"/>" />
			      <input type="submit" class="button" name="delete" onclick="bCancel=true;return confirmDelete('folderObject')" value="<fmt:message key="button.delete"/>" />
		   			<input type="submit" class="button" name="cancel" onclick="bCancel=true" value="<fmt:message key="button.cancel"/>" />
		      </c:if>
				</td>
			</tr>
		</c:set>
		<form method="post" action="<c:url value="/fileForm.action"/>" id="fileForm" enctype="multipart/form-data" onsubmit="return onFormSubmit(this)">
			<spring:bind path="fileObject.parentId">
		 	<p><h3><fmt:message key="fileObject.parentid"/>: <c:out value="${status.value}"/></h3></p>
			<input type="hidden" 
			  		id="parentId" 
			  		name="parentId" 
			  		value="<c:out value="${status.value}"/>">
			</spring:bind> 
			<spring:bind path="fileObject.uuid">
			<input type="hidden" 
			  		id="uuid" 
			  		name="uuid" 
			  		value="<c:out value="${status.value}"/>">
			</spring:bind> 
			<input type="hidden" 
			  		id="path" 
			  		name="path" 
			  		value="<c:out value="${fileObject.filePath}"/>">
			<c:if test="${param.method != 'add'}">
				<spring:bind path="fileObject.filePath">
				<input type="hidden" 
				  		id="filePath" 
				  		name="filePath" 
				  		value="<c:out value="${status.value}"/>">
				</spring:bind> 
			<table>
				<tr>
					<td><fmt:message key="fileObject.creationTime"/>:</td>
					<td><fmt:formatDate value="${fileObject.creationDate.time}" pattern="${datetimeformat}"/></td>
				</tr>
			</table>	
			<table>
				<tr>
					<td><fmt:message key="fileObject.modificationDate"/>:</td>
					<td><fmt:formatDate value="${fileObject.modificationDate.time}" pattern="${datetimeformat}"/></td>
				</tr>
			</table>	
		 	</c:if>
			<!-- input type="hidden" name="from" value="<c:out value="${param.from}"/>" / -->
			<input type="hidden" name="method" value="<c:out value="${param.method}"/>" />
			<table class="detail">
			<tr>
		       	<th width="15%">
		        	<mcaps:label key="fileObject.name"/>
		        </th>
				<td width="85%">
					<spring:bind path="fileObject.name">
						<input type="text" maxlength="100" width="100%" size="100"
				  			id="<c:out value="${status.expression}"/>" 
				  			name="<c:out value="${status.expression}"/>" 
				  			value="<c:out value="${fn:substringBefore(status.value,'.')}"/>">
			        		<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
					</spring:bind> 
				</td>
			</tr>
			<tr>
		       	<th width="15%">
		        	<mcaps:label key="fileObject.sourceFile"/>
		        </th>
				<td width="85%">
					<spring:bind path="fileObject.sourceFile">
						<input type="hidden" id="<c:out value="${status.expression}"/>" 
							name="<c:out value="${status.expression}"/>" 
							value="<c:out value="${fileObject.name}"/>">
						<input type="file" name="uploadFile" size="85" >
						<span class="fieldError"><c:out value="${status.errorMessage}"/></span>
					</spring:bind> 
				</td>
			</tr>
			</table>
			<table class="detail">
				<c:out value="${pageButtons}" escapeXml="false" />
			</table>
		</form>
	
<script type="text/javascript">
highlightFormElements();

<%-- if we're doing an add, change the focus --%>

<c:set var="focus" value="name"/>

var focusControl = document.forms["fileForm"].elements["<c:out value="${focus}"/>"];

<!-- This is here so we can exclude the selectAll call when roles is hidden -->
function onFormSubmit(theForm) {
	if (theForm.name.value.indexOf(".") > -1){
		alert("Invalid file name. Please input only alphabets.");
		return false;
	}
	if (theForm.uploadFile.value != ""){
		theForm.sourceFile.value = theForm.uploadFile.value;
		var sourceVal = theForm.sourceFile.value;
		if (theForm.name.value == ""){
			sourceVal = sourceVal.substring(sourceVal.lastIndexOf("\\")+1,sourceVal.length);
			sourceVal = sourceVal.substring(0,sourceVal.lastIndexOf("."));
			theForm.name.value = sourceVal;
		}
	}
<c:if test="${param.method == 'edit'}">
	<spring:bind path="fileObject.name">
	if (bCancel == false && theForm.uploadFile.value == "" && theForm.<c:out value="${status.expression}"/>.value == "<c:out value="${status.value}"/>") {
		alert ("No changes made.");
		return false;
	}
	</spring:bind> 
</c:if>
    return validateFileObject(theForm);
}


</script>

<v:javascript formName="fileObject" staticJavascript="false"/>
<script type="text/javascript"
      src="<c:url value="/scripts/validator.jsp"/>">
</script>
      
	</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?