mirror of
https://github.com/apache/struts.git
synced 2026-08-15 11:37:02 +00:00
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
This commit is contained in:
+57
@@ -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;
|
||||
}
|
||||
}
|
||||
+24
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
<%@taglib 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>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@taglib 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>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<%@taglib 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>
|
||||
|
||||
Reference in New Issue
Block a user