From 0889f1eecc4925ea14fcaeefa38cc69d972ebcea Mon Sep 17 00:00:00 2001 From: Toby Jee Date: Mon, 21 Aug 2006 14:25:31 +0000 Subject: [PATCH] WW-731 - added an example into showcase demostrating a simple usage of MessageStoreInterceptor git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@433252 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/SubmitApplication.java | 57 +++++++++++++++++++ ...plication-submitApplication-validation.xml | 24 ++++++++ .../src/main/resources/struts-validation.xml | 30 +++++++++- .../src/main/webapp/validation/index.jsp | 2 + .../storeErrorsAcrossRequestCancel.jsp | 21 +++++++ .../storeErrorsAcrossRequestExample.jsp | 35 ++++++++++++ .../validation/storeErrorsAcrossRequestOk.jsp | 23 ++++++++ 7 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java create mode 100644 apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml create mode 100644 apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp create mode 100644 apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp create mode 100644 apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp diff --git a/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java new file mode 100644 index 000000000..f6312905b --- /dev/null +++ b/apps/showcase/src/main/java/org/apache/struts2/showcase/validation/SubmitApplication.java @@ -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; + } +} diff --git a/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml b/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml new file mode 100644 index 000000000..0dbb123f9 --- /dev/null +++ b/apps/showcase/src/main/resources/org/apache/struts2/showcase/validation/SubmitApplication-submitApplication-validation.xml @@ -0,0 +1,24 @@ + + + + + + + You must provide a name + + + + + You must provide your age + + + 18 + 50 + Your age must be between 18 and 50 + + + + + diff --git a/apps/showcase/src/main/resources/struts-validation.xml b/apps/showcase/src/main/resources/struts-validation.xml index 6ee6c7780..0a79df597 100755 --- a/apps/showcase/src/main/resources/struts-validation.xml +++ b/apps/showcase/src/main/resources/struts-validation.xml @@ -93,8 +93,34 @@ /validation/successClientSideValidationExample.jsp - - + + + + + + + STORE + + + /validation/resubmitApplication.action + /validation/applicationOk.action + + + + RETRIEVE + + /validation/storeErrorsAcrossRequestExample.jsp + + + + RETRIEVE + + /validation/storeErrorsAcrossRequestOk.jsp + + + /validation/storeErrorsAcrossRequestCancel.jsp + + diff --git a/apps/showcase/src/main/webapp/validation/index.jsp b/apps/showcase/src/main/webapp/validation/index.jsp index d7a603683..5819fac93 100644 --- a/apps/showcase/src/main/webapp/validation/index.jsp +++ b/apps/showcase/src/main/webapp/validation/index.jsp @@ -23,6 +23,7 @@ +
  • Validation (basic)
  • @@ -34,6 +35,7 @@
  • Visitor Validator
  • Client side validation using JavaScript
  • Back To Showcase +
  • Store across request using MessageStoreInterceptor (Example)
diff --git a/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp new file mode 100644 index 000000000..ef6efcb49 --- /dev/null +++ b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestCancel.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + +<%@taglib prefix="s" uri="/tags" %> + + + +Insert title here + + + + + + + +

Application Canceled

+ + Try Again + + + diff --git a/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp new file mode 100644 index 000000000..1986e8c8d --- /dev/null +++ b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestExample.jsp @@ -0,0 +1,35 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@taglib prefix="s" uri="/tags" %> + + + + +Showcase - Validation - Store Errors Across Request Example + + +

+ 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. +

+

+ + + + + + + + + + + + + + + diff --git a/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp new file mode 100644 index 000000000..c60638f8d --- /dev/null +++ b/apps/showcase/src/main/webapp/validation/storeErrorsAcrossRequestOk.jsp @@ -0,0 +1,23 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> +<%@taglib prefix="s" uri="/tags" %> + + + + +Showcase - Validation - Store Errors Across Request Example + + + + + + + +

Ok !

+ + + Try Again + + + +