Author: tmjee
Date: Mon Aug 21 07:25:31 2006
New Revision: 433252

URL: http://svn.apache.org/viewvc?rev=433252&view=rev
Log:
WW-731
 - added an example into showcase demostrating a simple usage of 
MessageStoreInterceptor


Added:
    
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java
    
struts/struts2/trunk/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml
    
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp
    
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp
    
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp
Modified:
    struts/struts2/trunk/apps/showcase/src/main/resources/struts-validation.xml
    struts/struts2/trunk/apps/showcase/src/main/webapp/validation/index.jsp

Added: 
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java?rev=433252&view=auto
==============================================================================
--- 
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java
 (added)
+++ 
struts/struts2/trunk/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java
 Mon Aug 21 07:25:31 2006
@@ -0,0 +1,57 @@
+/*
+ * $Id: QuizAction.java 420385 2006-07-10 00:57:05Z mrdon $
+ *
+ * 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.struts2.showcase.validation;
+
+import com.opensymphony.xwork2.ActionSupport;
+
+/**
+ * 
+ * @version $Date$ $Id$
+ */
+public class SubmitApplication extends ActionSupport {
+       
+       private String name;
+       private Integer age;
+       
+       public void setName(String name) {
+               this.name = name;
+       }
+       public String getName() {
+               return this.name;
+       }
+       
+       public void setAge(Integer age) {
+               this.age = age;
+       }
+       public Integer getAge() {
+               return age;
+       }
+       
+       public String submitApplication() throws Exception {
+               return SUCCESS;
+       }
+       
+       public String applicationOk() throws Exception {
+               addActionMessage("Your application looks ok.");
+               return SUCCESS;
+       }
+       public String cancelApplication() throws Exception {
+               addActionMessage("So you have decided to cancel the 
application");
+               return SUCCESS;
+       }
+}

Added: 
struts/struts2/trunk/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml?rev=433252&view=auto
==============================================================================
--- 
struts/struts2/trunk/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml
 (added)
+++ 
struts/struts2/trunk/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml
 Mon Aug 21 07:25:31 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE validators PUBLIC
+               "-//OpenSymphony Group//XWork Validator 1.0//EN" 
+               "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd";>
+
+<validators>
+       <field name="name">
+               <field-validator type="requiredstring">
+                       <message>You must provide a name</message>
+               </field-validator>
+       </field>
+       <field name="age">
+               <field-validator type="required">
+                       <message>You must provide your age</message>
+               </field-validator>
+               <field-validator type="int">
+                       <param name="min">18</param>
+                       <param name="max">50</param>
+                       <message>Your age must be between 18 and 50</message>
+               </field-validator>
+       </field>
+</validators>
+
+

Modified: 
struts/struts2/trunk/apps/showcase/src/main/resources/struts-validation.xml
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/resources/struts-validation.xml?rev=433252&r1=433251&r2=433252&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/resources/struts-validation.xml 
(original)
+++ struts/struts2/trunk/apps/showcase/src/main/resources/struts-validation.xml 
Mon Aug 21 07:25:31 2006
@@ -93,8 +93,34 @@
                        
<result>/validation/successClientSideValidationExample.jsp</result>
                </action>
 
-
-
+               <!-- =========================================== -->
+               <!-- === Store Error Messages Across Request === -->
+               <!-- =========================================== -->
+               
+               <action name="submitApplication" 
class="org.apache.struts2.showcase.validation.SubmitApplication" 
method="submitApplication">
+                       <interceptor-ref name="store">
+                               <param name="operationMode">STORE</param>
+                       </interceptor-ref>
+                       <interceptor-ref name="defaultStack" />
+                       <result name="input" 
type="redirect">/validation/resubmitApplication.action</result>
+                       <result 
type="redirect">/validation/applicationOk.action</result>
+               </action>
+               <action name="resubmitApplication" 
class="org.apache.struts2.showcase.validation.SubmitApplication">
+                       <interceptor-ref name="store">
+                               <param name="operationMode">RETRIEVE</param>
+                       </interceptor-ref>
+                       
<result>/validation/storeErrorsAcrossRequestExample.jsp</result>
+               </action>
+               <action name="applicationOk" 
class="org.apache.struts2.showcase.validation.SubmitApplication" 
method="applicationOk">
+                       <interceptor-ref name="store">
+                               <param name="operationMode">RETRIEVE</param>
+                       </interceptor-ref>
+                       
<result>/validation/storeErrorsAcrossRequestOk.jsp</result>
+               </action>
+               <action name="cancelApplication" 
class="org.apache.struts2.showcase.validation.SubmitApplication" 
method="cancelApplication">
+                       
<result>/validation/storeErrorsAcrossRequestCancel.jsp</result>
+               </action>
+               
     </package>
 </struts>
        

Modified: 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/index.jsp
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/validation/index.jsp?rev=433252&r1=433251&r2=433252&view=diff
==============================================================================
--- struts/struts2/trunk/apps/showcase/src/main/webapp/validation/index.jsp 
(original)
+++ struts/struts2/trunk/apps/showcase/src/main/webapp/validation/index.jsp Mon 
Aug 21 07:25:31 2006
@@ -23,6 +23,7 @@
         <s:url id="visitorValidatorUrl" action="showVisitorValidatorsExamples" 
namespace="/validation" />
         <s:url id="clientSideValidationUrl" 
action="clientSideValidationExample" namespace="/validation" />
         <s:url id="backToShowcase" action="showcase" namespace="/" />
+        <s:url id="storeMessageAcrossRequestExample" 
value="/validation/storeErrorsAcrossRequestExample.jsp" />
         
         <ul>
             <li><s:a href="%{quizBasic}">Validation (basic)</s:a></li>
@@ -34,6 +35,7 @@
             <li><s:a href="%{visitorValidatorUrl}">Visitor Validator</s:a></li>
             <li><s:a href="%{clientSideValidationUrl}">Client side validation 
using JavaScript</s:a></li>
             <li><s:a href="%{backToShowcase}">Back To Showcase</s:a>
+            <li><s:a href="%{storeMessageAcrossRequestExample}">Store across 
request using MessageStoreInterceptor (Example)</s:a></li>
         </ul>
     </body>
 </html>

Added: 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp?rev=433252&view=auto
==============================================================================
--- 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp
 (added)
+++ 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp
 Mon Aug 21 07:25:31 2006
@@ -0,0 +1,21 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<[EMAIL PROTECTED] prefix="s" uri="/tags" %>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+
+       <s:actionmessage/>
+       <s:actionerror/>
+       <s:fielderror />
+
+       <h1>Application Canceled</h1>   
+       <s:url id="url" value="/validation/storeErrorsAcrossRequestExample.jsp" 
/>
+       <s:a href="%{#url}">Try Again</s:a>
+</body>
+</html>
+

Added: 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp?rev=433252&view=auto
==============================================================================
--- 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp
 (added)
+++ 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp
 Mon Aug 21 07:25:31 2006
@@ -0,0 +1,35 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<[EMAIL PROTECTED] prefix="s" uri="/tags" %>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Showcase - Validation - Store Errors Across Request Example</title>
+</head>
+<body>
+       <p>
+       This is an example demonstrating the use of MessageStoreInterceptor.
+       When this form is submited a redirect is issue both when there's a 
validation
+       error or not. Normally, when a redirect is issue the action messages / 
errors and
+       field errors stored in the action will be lost (due to an action lives 
+       only as long as a request). With a MessageStoreInterceptor in place and 
+       configured, the action errors / messages / field errors will be store 
and 
+       remains retrieveable even after a redirect.
+       </p>
+       <p/>
+       
+       <s:actionmessage/>
+       <s:actionerror/>
+       <s:fielderror />
+
+       <s:form action="submitApplication" namespace="/validation">
+               <s:textfield name="name" label="Name" />
+               <s:textfield name="age" label="Age" />
+               <s:submit />
+               <s:submit action="cancelApplication" value="%{'Cancel'}" />
+       </s:form>
+
+</body>
+</html>
+

Added: 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp?rev=433252&view=auto
==============================================================================
--- 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp
 (added)
+++ 
struts/struts2/trunk/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp
 Mon Aug 21 07:25:31 2006
@@ -0,0 +1,23 @@
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+    pageEncoding="UTF-8"%>
+<[EMAIL PROTECTED] prefix="s" uri="/tags" %>    
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Showcase - Validation - Store Errors Across Request Example</title>
+</head>
+<body>
+
+       <s:actionmessage/>
+       <s:actionerror/>
+       <s:fielderror />
+
+       <h2>Ok !</h2>
+       
+       <s:url id="url" value="/validation/storeErrorsAcrossRequestExample.jsp" 
/>
+       <s:a href="%{#id}">Try Again</s:a>
+
+</body>
+</html>
+


Reply via email to