From 4f37c65f789743a47d7771a2e5b9d72da4da211d Mon Sep 17 00:00:00 2001
From: Nils-Helge Garli
Date: Sun, 12 Aug 2007 13:02:27 +0000
Subject: [PATCH] Added example for model driven and file upload
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@565061 13f79535-47bb-0310-9956-ffa450edef68
---
.../example/FormExampleModelDriven.java | 37 +++++++++
.../example/fileupload/FileUploadAction.java | 81 +++++++++++++++++++
.../struts2/portlet/example/model/Name.java | 18 +++++
.../src/main/resources/struts-view.xml | 19 +++++
.../main/webapp/WEB-INF/view/fileUpload.jsp | 13 +++
.../webapp/WEB-INF/view/fileUploadSuccess.jsp | 14 ++++
.../view/formExampleInputModelDriven.jsp | 8 ++
.../src/main/webapp/WEB-INF/view/index.jsp | 2 +
8 files changed, 192 insertions(+)
create mode 100644 apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java
create mode 100644 apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java
create mode 100644 apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java
create mode 100644 apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp
create mode 100644 apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp
create mode 100644 apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp
diff --git a/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java
new file mode 100644
index 000000000..1eee98b24
--- /dev/null
+++ b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/FormExampleModelDriven.java
@@ -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 {
+
+ private Name name = new Name();
+
+ public Name getModel() {
+ return name;
+ }
+}
diff --git a/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java
new file mode 100644
index 000000000..c021714d3
--- /dev/null
+++ b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/fileupload/FileUploadAction.java
@@ -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. FileUploadAction
+ *
+ */
+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 the file name will be
+ // obtained through getter/setter of FileName
+ public String getUploadFileName() {
+ return fileName;
+ }
+ public void setUploadFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+
+ // since we are using the content type will be
+ // obtained through getter/setter of ContentType
+ public String getUploadContentType() {
+ return contentType;
+ }
+ public void setUploadContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+
+ // since we are using the File itself will be
+ // obtained through getter/setter of
+ 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;
+ }
+
+}
diff --git a/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java
new file mode 100644
index 000000000..1e59e1187
--- /dev/null
+++ b/apps/portlet/src/main/java/org/apache/struts2/portlet/example/model/Name.java
@@ -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;
+ }
+}
diff --git a/apps/portlet/src/main/resources/struts-view.xml b/apps/portlet/src/main/resources/struts-view.xml
index e8544e257..2edbaa864 100644
--- a/apps/portlet/src/main/resources/struts-view.xml
+++ b/apps/portlet/src/main/resources/struts-view.xml
@@ -27,6 +27,16 @@
/WEB-INF/view/formExample.jsp
+
+
+
+ /WEB-INF/view/formExampleInputModelDriven.jsp
+
+
+ /WEB-INF/view/formExample.jsp
+
+
@@ -44,6 +54,15 @@
/WEB-INF/view/formExampleInputValidation.jsp
+
+
+
+ /WEB-INF/view/fileUpload.jsp
+
+
+ /WEB-INF/view/fileUploadSuccess.jsp
+
+
diff --git a/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp b/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp
new file mode 100644
index 000000000..bf702bdbf
--- /dev/null
+++ b/apps/portlet/src/main/webapp/WEB-INF/view/fileUpload.jsp
@@ -0,0 +1,13 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+ Fileupload sample
+
+
+
+
+
+
+
+
+
+
diff --git a/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp b/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp
new file mode 100644
index 000000000..3c0259f8f
--- /dev/null
+++ b/apps/portlet/src/main/webapp/WEB-INF/view/fileUploadSuccess.jsp
@@ -0,0 +1,14 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+Fileupload sample
+
+
+
+ - ContentType:
+ - FileName:
+ - File:
+ - Caption:
+
+
+
+
diff --git a/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp b/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp
new file mode 100644
index 000000000..bbb852f54
--- /dev/null
+++ b/apps/portlet/src/main/webapp/WEB-INF/view/formExampleInputModelDriven.jsp
@@ -0,0 +1,8 @@
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+Input your name
+
+
+
+
+
diff --git a/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp b/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp
index 68dadac68..10bfcb212 100644
--- a/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp
+++ b/apps/portlet/src/main/webapp/WEB-INF/view/index.jsp
@@ -4,9 +4,11 @@
Here you'll find examples of what is possible with the Struts Portlet integration framework.
- ">A simple form
+- ">Model driven example
- ">Validation
- ">Token
- ">Spring integration
+- ">File upload
- ">FreeMarker
- ">Velocity
- ">Go to edit mode and see what's there