You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ni...@apache.org on 2007/08/12 15:02:29 UTC

svn commit: r565061 - in /struts/struts2/trunk/apps/portlet/src/main: java/org/apache/struts2/portlet/example/ java/org/apache/struts2/portlet/example/fileupload/ java/org/apache/struts2/portlet/example/model/ resources/ webapp/WEB-INF/view/

Author: nilsga
Date: Sun Aug 12 06:02:27 2007
New Revision: 565061

URL: http://svn.apache.org/viewvc?view=rev&rev=565061
Log:
Added example for model driven and file upload

Added:
    struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java
    struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/
    struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java
    struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/
    struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java
    struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp
    struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp
    struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp
Modified:
    struts/struts2/trunk/apps/portlet/src/main/resources/struts-view.xml
    struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp

Added: struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java (added)
+++ struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java Sun Aug 12 06:02:27 2007
@@ -0,0 +1,37 @@
+/*
+ * $Id: FormExample.java 471756 2006-11-06 15:01:43Z husted $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.struts2.portlet.example;
+
+import org.apache.struts2.portlet.example.model.Name;
+
+import com.opensymphony.xwork2.ActionSupport;
+import com.opensymphony.xwork2.ModelDriven;
+
+/**
+ */
+public class FormExampleModelDriven extends ActionSupport implements ModelDriven<Name> {
+    
+	private Name name = new Name();
+
+	public Name getModel() {
+		return name;
+	}
+}

Added: struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java (added)
+++ struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java Sun Aug 12 06:02:27 2007
@@ -0,0 +1,81 @@
+/*
+ * $Id: $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.struts2.portlet.example.fileupload;
+
+import java.io.File;
+
+import org.apache.struts2.dispatcher.DefaultActionSupport;
+
+/**
+ * File Upload example's action. <code>FileUploadAction</code>
+ *
+ */
+public class FileUploadAction extends DefaultActionSupport {
+
+    private static final long serialVersionUID = 5156288255337069381L;
+
+    private String contentType;
+    private File upload;
+    private String fileName;
+    private String caption;
+
+    // since we are using <s:file name="upload" .../> the file name will be
+    // obtained through getter/setter of <file-tag-name>FileName
+    public String getUploadFileName() {
+        return fileName;
+    }
+    public void setUploadFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+
+    // since we are using <s:file name="upload" ... /> the content type will be
+    // obtained through getter/setter of <file-tag-name>ContentType
+    public String getUploadContentType() {
+        return contentType;
+    }
+    public void setUploadContentType(String contentType) {
+        this.contentType = contentType;
+    }
+
+
+    // since we are using <s:file name="upload" ... /> the File itself will be
+    // obtained through getter/setter of <file-tag-name>
+    public File getUpload() {
+        return upload;
+    }
+    public void setUpload(File upload) {
+        this.upload = upload;
+    }
+
+
+    public String getCaption() {
+        return caption;
+    }
+    public void setCaption(String caption) {
+        this.caption = caption;
+    }
+
+    public String upload() throws Exception  {
+        return SUCCESS;
+    }
+
+}

Added: struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java (added)
+++ struts/struts2/trunk/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java Sun Aug 12 06:02:27 2007
@@ -0,0 +1,18 @@
+package org.apache.struts2.portlet.example.model;
+
+public class Name {
+	private String firstName;
+	private String lastName;
+	public String getFirstName() {
+		return firstName;
+	}
+	public void setFirstName(String firstName) {
+		this.firstName = firstName;
+	}
+	public String getLastName() {
+		return lastName;
+	}
+	public void setLastName(String lastName) {
+		this.lastName = lastName;
+	}
+}

Modified: struts/struts2/trunk/apps/portlet/src/main/resources/struts-view.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/resources/struts-view.xml?view=diff&rev=565061&r1=565060&r2=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/resources/struts-view.xml (original)
+++ struts/struts2/trunk/apps/portlet/src/main/resources/struts-view.xml Sun Aug 12 06:02:27 2007
@@ -27,6 +27,16 @@
 				/WEB-INF/view/formExample.jsp
 			</result>
 		</action>
+		
+		<action name="formExampleModelDriven"
+			class="org.apache.struts2.portlet.example.FormExampleModelDriven">
+			<result name="input">
+				/WEB-INF/view/formExampleInputModelDriven.jsp
+			</result>
+			<result name="success">
+				/WEB-INF/view/formExample.jsp
+			</result>
+		</action>
 
 		<action name="validationExample"
 			class="org.apache.struts2.portlet.example.FormExample" method="input">
@@ -42,6 +52,15 @@
 			</result>
 			<result name="input">
 				/WEB-INF/view/formExampleInputValidation.jsp
+			</result>
+		</action>
+		
+		<action name="fileUpload" class="org.apache.struts2.portlet.example.fileupload.FileUploadAction">
+			<result name="input">
+				/WEB-INF/view/fileUpload.jsp
+			</result>
+			<result name="success">
+				/WEB-INF/view/fileUploadSuccess.jsp
 			</result>
 		</action>
 

Added: struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp (added)
+++ struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp Sun Aug 12 06:02:27 2007
@@ -0,0 +1,13 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+    <h1>Fileupload sample</h1>
+
+	<s:actionerror />
+	<s:fielderror />
+    <s:form action="fileUpload" method="POST" enctype="multipart/form-data">
+        <s:file name="upload" label="File"/>
+        <s:textfield name="caption" label="Caption"/>
+        <s:submit />
+    </s:form>
+
+

Added: struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp (added)
+++ struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp Sun Aug 12 06:02:27 2007
@@ -0,0 +1,14 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<h1>Fileupload sample</h1>
+
+<p>
+    <ul>
+        <li>ContentType: <s:property value="uploadContentType" /></li>
+        <li>FileName: <s:property value="uploadFileName" /></li>
+        <li>File: <s:property value="upload" /></li>
+        <li>Caption:<s:property value="caption" /></li>
+    </ul>
+</p>
+
+

Added: struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp?view=auto&rev=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp (added)
+++ struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp Sun Aug 12 06:02:27 2007
@@ -0,0 +1,8 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<H2>Input your name</H2>
+<s:form action="formExampleModelDriven" method="POST">
+    <s:textfield label="First name" name="firstName" value="%{firstName}"/>
+    <s:textfield label="Last name" name="lastName" value="%{lastName}"/>
+    <s:submit value="Submit the form"/>
+</s:form>

Modified: struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp?view=diff&rev=565061&r1=565060&r2=565061
==============================================================================
--- struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp (original)
+++ struts/struts2/trunk/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp Sun Aug 12 06:02:27 2007
@@ -4,9 +4,11 @@
 Here you'll find examples of what is possible with the Struts Portlet integration framework.
 <ul>
 <li><a href="<s:url action="formExample"/>">A simple form</a></li>
+<li><a href="<s:url action="formExampleModelDriven" method="input"/>">Model driven example</li>
 <li><a href="<s:url action="validationExample"/>">Validation</a></li>
 <li><a href="<s:url action="tokenExample"/>">Token</a></li>
 <li><a href="<s:url action="springExample"/>">Spring integration</a></li>
+<li><a href="<s:url action="fileUpload" method="input"/>">File upload</li>
 <li><a href="<s:url action="freeMarkerExample"/>">FreeMarker</a></li>
 <li><a href="<s:url action="velocityHelloWorld"/>">Velocity</a></li>
 <li><a href="<s:url action="index" portletMode="edit"/>">Go to edit mode and see what's there</a></li>