struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r497343 - in /struts/maven/trunk: struts2-archetype-dbportlet/src/main/resources/META-INF/ struts2-archetype-dbportlet/src/main/resources/archetype-resources/ struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/...
Date Thu, 18 Jan 2007 08:20:35 GMT
Author: mrdon
Date: Thu Jan 18 00:20:34 2007
New Revision: 497343

URL: http://svn.apache.org/viewvc?view=rev&rev=497343
Log:
Finished up simple database portlet archetype, minor cleanups to blank portlet archetype

Added:
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml
Modified:
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp
    struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
    struts/maven/trunk/struts2-archetype-portlet/src/main/resources/META-INF/archetype.xml
    struts/maven/trunk/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/resources/struts.xml

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/META-INF/archetype.xml
Thu Jan 18 00:20:34 2007
@@ -8,6 +8,7 @@
   </sources>
   <resources>
   	<resource>src/main/resources/struts.xml</resource>
+	<resource>src/main/webapp/index.jsp</resource>
 	<resource>src/main/webapp/WEB-INF/web.xml</resource>
 	<resource>src/main/webapp/WEB-INF/portlet.xml</resource>
 	<resource>src/main/webapp/WEB-INF/applicationContext.xml</resource>

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/pom.xml
Thu Jan 18 00:20:34 2007
@@ -6,9 +6,9 @@
 	<artifactId>${artifactId}</artifactId>
 	<packaging>war</packaging>
 	<version>${version}</version>
-	<name>Struts 2 Portlet</name>
+	<name>Struts 2 Database Portlet</name>
 	<url>http://www.myComp.com</url>
-	<description>Struts 2 Portlet</description>
+	<description>Struts 2 Database Portlet</description>
 	
 	<dependencies>
 		<!-- Junit -->
@@ -35,6 +35,25 @@
             <groupId>commons-lang</groupId>
             <artifactId>commons-lang</artifactId>
             <version>2.1</version>
+        </dependency>
+
+        <!-- Spring -->
+        <dependency>
+            <groupId>org.apache.struts</groupId>
+            <artifactId>struts2-spring-plugin</artifactId>
+            <version>2.0.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
+            <version>2.0.1</version>
+        </dependency>
+
+        <!-- Database driver (change for your specific database) -->
+         <dependency>
+            <groupId>hsqldb</groupId>
+            <artifactId>hsqldb</artifactId>
+            <version>1.8.0.7</version>
         </dependency>
 
 		<!-- Servlet, Jsp, and Portlet API's -->

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/java/view/IndexAction.java
Thu Jan 18 00:20:34 2007
@@ -1,20 +1,51 @@
 package ${package}.view;
 
 import org.apache.struts2.dispatcher.DefaultActionSupport;
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
+
+import javax.sql.DataSource;
+import java.util.Map;
+import java.util.List;
 
 /**
- *
+ * Loads and displays the contents of a database table
  */
 public class IndexAction extends DefaultActionSupport {
-    private String name = "My Name";
+
+    private static boolean initialized = false;
+    private DataSource ds;
+    private static List<Map<String,Object>> data;
+    private static long lastLoaded;
+    private static long CACHE_TIME = 1000 * 60;
+
+    public void setDataSource(DataSource ds) {
+
+        // Initializes the in-memory database (not necessary in production)
+        if (!initialized) {
+            SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds);
+            jt.update("CREATE TABLE sample_table ( id INTEGER IDENTITY, str_col VARCHAR(256),
num_col INTEGER)");
+            jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Ford', 100)");
+            jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Toyota', 200)");
+            jt.update("INSERT INTO sample_table(str_col,num_col) VALUES('Mazda', 300)");
+            initialized = true;
+        }
+        this.ds = ds;
+    }
 
     public String execute() {
-        // Preform any logic here
 
+        // Only refresh the data every minute as needed
+        long now = System.currentTimeMillis();
+        if (lastLoaded + CACHE_TIME < now) {
+            SimpleJdbcTemplate jt = new SimpleJdbcTemplate(ds);
+            data = jt.queryForList("SELECT * FROM sample_table");
+            lastLoaded = now;
+        }
         return SUCCESS;
     }
 
-    public String getName() {
-        return name;
+    public List<Map<String,Object>> getData() {
+        return data;
     }
 }
+

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
Thu Jan 18 00:20:34 2007
@@ -7,6 +7,7 @@
 <struts>
     <constant name="struts.codebehind.defaultPackage" value="struts-portlet-default" />
     <constant name="struts.codebehind.pathPrefix" value="/WEB-INF/" />
+    <constant name="struts.devMode" value="true" />
 
 	<include file="struts-portlet-default.xml" />
 </struts>

Added: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml?view=auto&rev=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml
(added)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/applicationContext.xml
Thu Jan 18 00:20:34 2007
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<!--
+    Defines the datasource that will be injected into your Actions
+-->
+
+<beans default-autowire="byName">
+
+    <!-- Change for your database -->
+    <bean id="dataSource"
+        class="org.springframework.jdbc.datasource.DriverManagerDataSource"
+        destroy-method="close">
+        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+        <property name="url" value="jdbc:hsqldb:mem:example"/>
+        <property name="username" value="sa"/>
+        <property name="password" value=""/>
+    </bean>
+
+</beans>

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/portlet.xml
Thu Jan 18 00:20:34 2007
@@ -1,10 +1,10 @@
 <portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
id="struts-portlet">
-  <portlet id="StrutsPortlet">
-    <description xml:lang="EN">Blank Struts Portlet</description>
-    <portlet-name>StrutsPortlet</portlet-name>
-    <display-name xml:lang="EN">Blank Struts Portlet</display-name>
+  <portlet id="StrutsDBPortlet">
+    <description xml:lang="EN">Struts Database Portlet</description>
+    <portlet-name>StrutsDBPortlet</portlet-name>
+    <display-name xml:lang="EN">Struts Database Portlet</display-name>
     
     <portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class>
 
@@ -54,9 +54,9 @@
     <supported-locale>en</supported-locale>
 
     <portlet-info>
-      <title>Struts Blank Porlet</title>
-      <short-title>SB</short-title>
-      <keywords>struts,portlet</keywords>
+      <title>Struts Database Porlet</title>
+      <short-title>DB</short-title>
+      <keywords>struts,portlet,database</keywords>
     </portlet-info>
   </portlet>
   

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/view/index.jsp
Thu Jan 18 00:20:34 2007
@@ -1,12 +1,18 @@
 <%@ taglib prefix="s" uri="/struts-tags" %>
-<H2>Welcome to the Struts blank portlet</H2>
+<H2>Welcome to the Struts data table portlet</H2>
 <p/>
-This is an example of accessing the action's properties:
+This a simple table showing the database data:
 <table>
  <tr>
   <th>Name</th>
-  <td><s:property value="%{name}" /></td>
+  <th>Value</th>
  </tr>
+ <s:iterator id="row" value="%{data}">
+ <tr>
+  <td><s:property value="%{STR_COL}" /></td>
+  <td><s:property value="%{NUM_COL}" /></td>
+ </tr>
+ </s:iterator>
 </table>
 <ul>
 <li><a href="<s:url action="index" portletMode="edit"/>">Go to edit mode
and see what's there</a></li>

Modified: struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
(original)
+++ struts/maven/trunk/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
Thu Jan 18 00:20:34 2007
@@ -2,6 +2,11 @@
 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
 <web-app>
 
+    <context-param>
+		<param-name>contextConfigLocation</param-name>
+		<param-value>/WEB-INF/applicationContext*.xml</param-value>
+	</context-param>
+
     <filter id="filterdispatcher">
 		<filter-name>struts</filter-name>
 		<filter-class>
@@ -17,8 +22,14 @@
 		<filter-name>struts</filter-name>
 		<url-pattern>/*</url-pattern>
 	</filter-mapping>
+ 
+    <listener>
+		<listener-class>
+			org.springframework.web.context.ContextLoaderListener
+		</listener-class>
+	</listener>
     
-	<listener>
+    <listener>
 		<listener-class>
 			org.apache.struts2.portlet.context.ServletContextHolderListener
 		</listener-class>

Modified: struts/maven/trunk/struts2-archetype-portlet/src/main/resources/META-INF/archetype.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-portlet/src/main/resources/META-INF/archetype.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-portlet/src/main/resources/META-INF/archetype.xml
(original)
+++ struts/maven/trunk/struts2-archetype-portlet/src/main/resources/META-INF/archetype.xml
Thu Jan 18 00:20:34 2007
@@ -8,6 +8,7 @@
   </sources>
   <resources>
   	<resource>src/main/resources/struts.xml</resource>
+	<resource>src/main/webapp/index.jsp</resource>
 	<resource>src/main/webapp/WEB-INF/web.xml</resource>
 	<resource>src/main/webapp/WEB-INF/portlet.xml</resource>
 	<resource>src/main/webapp/WEB-INF/view/index.jsp</resource>

Modified: struts/maven/trunk/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
URL: http://svn.apache.org/viewvc/struts/maven/trunk/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/resources/struts.xml?view=diff&rev=497343&r1=497342&r2=497343
==============================================================================
--- struts/maven/trunk/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
(original)
+++ struts/maven/trunk/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/resources/struts.xml
Thu Jan 18 00:20:34 2007
@@ -7,6 +7,7 @@
 <struts>
     <constant name="struts.codebehind.defaultPackage" value="struts-portlet-default" />
     <constant name="struts.codebehind.pathPrefix" value="/WEB-INF/" />
+    <constant name="struts.devMode" value="true" />
 
 	<include file="struts-portlet-default.xml" />
 </struts>



Mime
View raw message