struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r415098 - in /struts/action2/trunk/apps/showcase/src/main: java/org/apache/struts/action2/showcase/action/ java/org/apache/struts/action2/showcase/jsf/ resources/ webapp/WEB-INF/ webapp/WEB-INF/decorators/ webapp/jsf/ webapp/jsf/employee/
Date Sun, 18 Jun 2006 05:47:31 GMT
Author: mrdon
Date: Sat Jun 17 22:47:30 2006
New Revision: 415098

URL: http://svn.apache.org/viewvc?rev=415098&view=rev
Log:
Changed JSF example to use common CRUD actions and DAO's, reorganizes
pages to match other example

WW-1320

Added:
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/JsfEmployeeAction.java
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/edit.jsp
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/list.jsp
Removed:
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/EditEmployeeAction.java
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/Employee.java
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/EmployeeDao.java
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/ListEmployeesAction.java
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/editEmployee.jsp
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/listEmployees.jsp
Modified:
    struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/action/EmployeeAction.java
    struts/action2/trunk/apps/showcase/src/main/resources/xwork-jsf.xml
    struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
    struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml
    struts/action2/trunk/apps/showcase/src/main/webapp/jsf/index.jsp

Modified: struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/action/EmployeeAction.java
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/action/EmployeeAction.java?rev=415098&r1=415097&r2=415098&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/action/EmployeeAction.java
(original)
+++ struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/action/EmployeeAction.java
Sat Jun 17 22:47:30 2006
@@ -31,7 +31,7 @@
 import java.util.List;
 
 /**
- * EditEmployeeAction.
+ * JsfEmployeeAction.
  */
 
 public class EmployeeAction extends AbstractCRUDAction implements Preparable {
@@ -83,7 +83,7 @@
 
     public void setEmployeeDao(EmployeeDao employeeDao) {
         if (log.isDebugEnabled()) {
-            log.debug("EditEmployeeAction - [setEmployeeDao]: employeeDao injected.");
+            log.debug("JsfEmployeeAction - [setEmployeeDao]: employeeDao injected.");
         }
         this.employeeDao = employeeDao;
     }

Added: struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/JsfEmployeeAction.java
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/JsfEmployeeAction.java?rev=415098&view=auto
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/JsfEmployeeAction.java
(added)
+++ struts/action2/trunk/apps/showcase/src/main/java/org/apache/struts/action2/showcase/jsf/JsfEmployeeAction.java
Sat Jun 17 22:47:30 2006
@@ -0,0 +1,119 @@
+/*
+ * $Id: QuizAction.java 394498 2006-04-16 15:28:06Z tmjee $
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.struts.action2.showcase.jsf;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.struts.action2.showcase.action.EmployeeAction;
+import org.apache.struts.action2.showcase.dao.SkillDao;
+import org.apache.struts.action2.showcase.model.Employee;
+import org.apache.struts.action2.showcase.model.Skill;
+
+/**
+ * Overriding the EmployeeAction to main provide getters returning the data in
+ * the form required by the JSF components
+ */
+public class JsfEmployeeAction extends EmployeeAction {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Creating a default employee and main skill, since the JSF EL can't handle
+     * creating new objects as necessary
+     * 
+     */
+    public JsfEmployeeAction() {
+        Employee e = new Employee();
+        e.setMainSkill(new Skill());
+        setCurrentEmployee(e);
+    }
+
+    private SkillDao skillDao;
+
+    public void setSkillDao(SkillDao skillDao) {
+        this.skillDao = skillDao;
+    }
+
+    /**
+     * Returning a List because the JSF dataGrid can't handle a Set for some
+     * reason
+     */
+    @Override
+    public Collection getAvailableItems() {
+        return new ArrayList(super.getAvailableItems());
+    }
+
+    /**
+     * Changing the String array into a Map
+     */
+    public Map<String, String> getAvailablePositionsAsMap() {
+        Map<String, String> map = new LinkedHashMap<String, String>();
+        for (String val : super.getAvailablePositions()) {
+            map.put(val, val);
+        }
+        return map;
+    }
+
+    /**
+     * Converting the list into a map
+     */
+    public Map getAvailableLevelsAsMap() {
+        Map map = new LinkedHashMap();
+        for (Object val : super.getAvailableLevels()) {
+            map.put(val, val);
+        }
+        return map;
+    }
+
+    /**
+     * Converting the Skill object list into a map
+     */
+    public Map<String, String> getAvailableSkills() {
+        Map<String, String> map = new HashMap<String, String>();
+        for (Object val : skillDao.findAll()) {
+            Skill skill = (Skill) val;
+            map.put(skill.getDescription(), skill.getName());
+        }
+        return map;
+    }
+
+    /**
+     * Gets the selected Skill objects as a list
+     */
+    public List<String> getSelectedSkillsAsList() {
+        System.out.println("asked for skills");
+        List<String> list = new ArrayList<String>();
+        List skills = super.getSelectedSkills();
+        if (skills != null) {
+            for (Object val : skills) {
+                if (val instanceof Skill) {
+                    list.add(((Skill) val).getDescription());
+                } else {
+                    Skill skill = skillDao.getSkill((String) val);
+                    list.add(skill.getDescription());
+                }
+            }
+        }
+        return list;
+    }
+}

Modified: struts/action2/trunk/apps/showcase/src/main/resources/xwork-jsf.xml
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/resources/xwork-jsf.xml?rev=415098&r1=415097&r2=415098&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/resources/xwork-jsf.xml (original)
+++ struts/action2/trunk/apps/showcase/src/main/resources/xwork-jsf.xml Sat Jun 17 22:47:30
2006
@@ -3,20 +3,31 @@
     <include file="struts-default.xml"/>
     <include file="struts-jsf.xml"/>
 
-    <package name="jsf" extends="struts-default, struts-jsf" namespace="/jsf">
-    
-        <action name="listEmployees" class="org.apache.struts.action2.showcase.jsf.ListEmployeesAction">
-            <interceptor-ref name="jsfStack"/>
-            <result name="success" type="jsf" />
+	<package name="jsf" extends="struts-default, struts-jsf" namespace="/jsf">
+		<interceptors>
+            <interceptor-stack name="jsfFullStack">
+				<interceptor-ref name="params" />
+                <interceptor-ref name="basicStack"/>
+                <interceptor-ref name="jsfStack"/>
+            </interceptor-stack>
+		</interceptors>
+		
+		<default-interceptor-ref name="jsfFullStack"/>
+    </package>
+				
+    <package name="jsf.employee" extends="jsf" namespace="/jsf/employee">
+
+		<action name="list" class="org.apache.struts.action2.showcase.jsf.JsfEmployeeAction"
method="list">
+			<result name="success" type="jsf" />
         </action>
-    
-        <action name="editEmployee" class="org.apache.struts.action2.showcase.jsf.EditEmployeeAction">
-            <interceptor-ref name="basicStack"/>
-            <interceptor-ref name="jsfStack"/>
+        <action name="edit" class="org.apache.struts.action2.showcase.jsf.JsfEmployeeAction">
             <result name="success" type="jsf" />
-            <result name="index" type="redirect-action">listEmployees</result>
         </action>
-
+        <action name="delete" class="org.apache.struts.action2.showcase.action.EmployeeAction"
method="delete">
+			<result name="error" type="redirect">list.action</result>
+            <result type="redirect">list.action</result>
+        </action>
+		
     </package>
 
 </xwork>

Modified: struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp?rev=415098&r1=415097&r2=415098&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp (original)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp Sat Jun
17 22:47:30 2006
@@ -76,7 +76,7 @@
                     <li><a href="<saf:url value="/token/index.jsp"/>">Token</a></li>
                     <li><a href="<saf:url value="/filedownload/index.jsp"/>">File
Download</a></li>
                     <li><a href="<saf:url value="/conversion/index.jsp"/>"/>Conversion</a></li>
-                    <li><a href="<saf:url action="index" namespace="/jsf"/>">JSF</a></li>
+                    <li><a href="<saf:url value="/jsf/index.jsp"/>">JSF</a></li>
                     <li><a href="<saf:url value="/freemarker/index.jsp"/>">Freemarker</a>
                     <li><a href="<saf:url value="/chat/index.jsp"/>">Chat
(AJAX)</a>
                     <li class="last"><a href="<saf:url value="/help.jsp"/>">Help</a></li>

Modified: struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml?rev=415098&r1=415097&r2=415098&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml (original)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/WEB-INF/web.xml Sat Jun 17 22:47:30
2006
@@ -42,11 +42,11 @@
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
 	
-	<listener>
-    <listener-class>
-      org.apache.myfaces.webapp.StartupServletContextListener
-    </listener-class>
-  </listener>
+    <listener>
+        <listener-class>
+          org.apache.myfaces.webapp.StartupServletContextListener
+        </listener-class>
+    </listener>
 	
     <!-- SNIPPET START: dwr -->
 
@@ -67,9 +67,9 @@
   	</servlet>
 
   	<!-- JavaServer Faces Servlet Mapping, not called directly -->
-  	<servlet-mapping>
-    	<servlet-name>faces</servlet-name>
-    	<url-pattern>*.action</url-pattern>
+    	<servlet-mapping>
+        <servlet-name>faces</servlet-name>
+        <url-pattern>*.action</url-pattern>
   	</servlet-mapping>
 
     <servlet-mapping>

Added: struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/edit.jsp
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/edit.jsp?rev=415098&view=auto
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/edit.jsp (added)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/edit.jsp Sat Jun 17 22:47:30
2006
@@ -0,0 +1,106 @@
+<%--
+
+ Copyright 2006 The Apache Software Foundation.
+ 
+ Licensed 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.
+
+ $Id: welcome.jsp 371852 2006-01-24 07:25:10Z craigmcc $
+
+--%>
+
+<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
+<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
+
+<f:view>
+
+<html>
+<!--  todo: make header variable -->
+  <head>
+    <title>JSF Integration Examples</title>
+  </head>
+
+  <body>
+  
+  	<h1>Modify Employee</h1>
+  	
+  	<h:form>
+  		<h:inputHidden value="#{action.currentEmployee.empId}" />
+  		<h:panelGrid columns="3">
+  		    <h:outputText value="Employee Id:" />
+  			<h:inputText id="id" size="5" value="#{action.currentEmployee.empId}" required="true"
/>
+  			<h:message for="id" />
+  			
+  			<h:outputText value="First Name:" />
+  			<h:inputText id="firstName" size="30" value="#{action.currentEmployee.firstName}"
required="true">
+  			    <f:validateLength minimum="2" maximum="30" />
+  			</h:inputText>
+  			<h:message for="firstName" />
+  			
+  			<h:outputText value="Last Name:" />
+  			<h:inputText id="lastName" size="30" value="#{action.currentEmployee.lastName}" required="true">
+  			    <f:validateLength minimum="2" maximum="30" />
+  			</h:inputText>
+  			<h:message for="lastName" />
+  			
+  			<h:outputText value="Salary:" />
+  			<h:inputText id="salary" size="10" value="#{action.currentEmployee.salary}" />
+  			<h:message for="salary" />
+  			
+  			<h:outputText value="Married:" />
+  			<h:selectBooleanCheckbox id="married" value="#{action.currentEmployee.married}" />
+  			<h:message for="married" />
+  			
+  			<h:outputText value="Position:" />
+  			<h:selectOneMenu id="position" value="#{action.currentEmployee.position}">
+  		        <f:selectItems value="#{action.availablePositionsAsMap}" />
+  			</h:selectOneMenu>
+  			<h:message for="position" />
+  			
+  			<h:outputText value="Main Skill:" />
+  			<h:selectOneMenu id="mainSkill" value="#{action.currentEmployee.mainSkill.name}">
+  			    <f:selectItems value="#{action.availableSkills}" />
+  			</h:selectOneMenu>
+  			<h:message for="mainSkill" />
+  			
+  			<h:outputText value="Other Skills:" />
+  			<h:selectManyListbox id="otherSkills" value="#{action.selectedSkills}" >
+  			    <f:selectItems value="#{action.availableSkills}" />
+  			</h:selectManyListbox>
+  			<h:message for="otherSkills" />
+  			
+  			<h:outputText value="Password:" />
+  			<h:inputSecret id="password" value="#{action.currentEmployee.password}" />
+  			<h:message for="password" />
+  			
+  			<h:outputText value="Level:" />
+  			<h:selectOneRadio id="level" value="#{action.currentEmployee.level}" >
+  			    <f:selectItems value="#{action.availableLevelsAsMap}" />
+  			</h:selectOneRadio>
+  			<h:message for="level" />
+  			
+  			<h:outputText value="Comment:" />
+  			<h:inputTextarea id="comment" value="#{action.currentEmployee.comment}" cols="50"
rows="3" />
+  			<h:message for="comment" />
+  		</h:panelGrid>
+  		
+  		<h:commandButton value="Save" action="#{action.save}" />
+  		<br /><br />
+  		<h:outputLink value="list.action">
+  			<h:outputText value="Back" />
+  		</h:outputLink>
+  	</h:form>
+  </body>
+
+</html>
+
+</f:view>
\ No newline at end of file

Added: struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/list.jsp
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/list.jsp?rev=415098&view=auto
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/list.jsp (added)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/jsf/employee/list.jsp Sat Jun 17 22:47:30
2006
@@ -0,0 +1,69 @@
+<%--
+
+ Copyright 2006 The Apache Software Foundation.
+ 
+ Licensed 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.
+
+ $Id: welcome.jsp 371852 2006-01-24 07:25:10Z craigmcc $
+
+--%>
+
+<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
+<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
+
+<f:view>
+
+<html>
+<head><title>Available Employees</title></head>
+
+<body>
+<h1>Available Employees</h1>
+  	
+  	<h:dataTable value="#{action.availableItems}" var="e">
+  		<h:column>
+  			<f:facet name="header">
+  				<h:outputText value="Id" />
+  			</f:facet>
+  			<h:outputLink value="edit.action">
+  				<f:param name="empId" value="#{e.empId}" />
+  				<h:outputText value="#{e.empId}" />
+  			</h:outputLink>	
+  		</h:column>
+		<h:column>
+  			<f:facet name="header">
+  				<h:outputText value="First Name" />
+  			</f:facet>
+  			<h:outputText value="#{e.firstName}" />
+  		</h:column>
+  		<h:column>
+  			<f:facet name="header">
+  				<h:outputText value="Last Name" />
+  			</f:facet>
+  			<h:outputText value="#{e.lastName}" />
+  		</h:column>
+  	</h:dataTable>	
+  	
+  	<p>
+  	<h:outputLink value="edit.action">
+  		<h:outputText value="Create new Employee" />
+  	</h:outputLink>
+  	</p>
+  	
+  	<h:outputLink value="../../showcase.action">
+  		<h:outputText value="Back to Showcase Startpage" />
+  	</h:outputLink>
+  </body>
+
+</html>
+
+</f:view>
\ No newline at end of file

Modified: struts/action2/trunk/apps/showcase/src/main/webapp/jsf/index.jsp
URL: http://svn.apache.org/viewvc/struts/action2/trunk/apps/showcase/src/main/webapp/jsf/index.jsp?rev=415098&r1=415097&r2=415098&view=diff
==============================================================================
--- struts/action2/trunk/apps/showcase/src/main/webapp/jsf/index.jsp (original)
+++ struts/action2/trunk/apps/showcase/src/main/webapp/jsf/index.jsp Sat Jun 17 22:47:30 2006
@@ -11,14 +11,14 @@
 The following pages show how Struts Action 2 and JSF components can work together,
 each doing what they do best.
 </p>
-  	
+
 <p>
 	<ul>
-		<li><saf:url id="url" namespace="/jsf" action="listEmployees"/><saf:a href="%{url}">List
available Employees</saf:a></li>
-        <li><saf:url id="url" namespace="/jsf" action="editEmployee"/><saf:a
href="%{url}">Create/Edit Employee</saf:a></li>
+        <li><saf:url id="url" namespace="/jsf/employee" action="list"/><saf:a
href="%{url}">List available Employees</saf:a></li>
+        <li><saf:url id="url" namespace="/jsf/employee" action="edit"/><saf:a
href="%{url}">Create/Edit Employee</saf:a></li>
 	</ul>
 </p>
-<p>
+
 
 </body>
-</html>
\ No newline at end of file
+</html>



Mime
View raw message