This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/struts-examples.git
The following commit(s) were added to refs/heads/master by this push: new 1c6ff24 WW-4940 Adds an example app how to customise validation messages 1c6ff24 is described below commit 1c6ff24bb6d6e9c1aca4be48c1d59e85e47bea31 Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Tue Jun 5 10:28:50 2018 +0200 WW-4940 Adds an example app how to customise validation messages --- pom.xml | 5 +- validation-messages/pom.xml | 39 ++++++++++++++ .../struts/validation_messages/ExampleSupport.java | 6 +++ .../apache/struts/validation_messages/Login.java | 59 ++++++++++++++++++++++ validation-messages/src/main/resources/log4j2.xml | 16 ++++++ .../validation_messages/Login-validation.xml | 21 ++++++++ .../struts/validation_messages/package.properties | 4 ++ .../validation_messages/package_es.properties | 4 ++ validation-messages/src/main/resources/struts.xml | 34 +++++++++++++ .../src/main/webapp/WEB-INF/Login.jsp | 15 ++++++ .../src/main/webapp/WEB-INF/Menu.jsp | 3 ++ .../src/main/webapp/WEB-INF/Missing.jsp | 11 ++++ .../src/main/webapp/WEB-INF/web.xml | 23 +++++++++ validation-messages/src/main/webapp/index.html | 10 ++++ 14 files changed, 248 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bd9e91c..ce77ea2 100644 --- a/pom.xml +++ b/pom.xml @@ -83,10 +83,11 @@ <module>type-conversion</module> <module>unit-testing</module> <module>using-tags</module> + <module>validation-messages</module> <module>wildcard-method-selection</module> <module>wildcard-regex</module> <module>unknown-handler</module> - </modules> + </modules> <dependencies> @@ -167,4 +168,4 @@ </repository> </repositories> -</project> +</project> \ No newline at end of file diff --git a/validation-messages/pom.xml b/validation-messages/pom.xml new file mode 100644 index 0000000..131dbb7 --- /dev/null +++ b/validation-messages/pom.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>struts-examples</artifactId> + <groupId>org.apache.struts</groupId> + <version>1.0.0</version> + </parent> + + <artifactId>validation-messages</artifactId> + <name>validation-messages</name> + <description>Struts 2 example application how to customise validation messages</description> + + <packaging>war</packaging> + + <build> + <finalName>validation-messages</finalName> + <plugins> + <plugin> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>${jetty-plugin.version}</version> + <configuration> + <webApp> + <contextPath>/${project.artifactId}</contextPath> + </webApp> + <stopKey>CTRL+C</stopKey> + <stopPort>8999</stopPort> + <scanIntervalSeconds>10</scanIntervalSeconds> + <scanTargets> + <scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget> + </scanTargets> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/validation-messages/src/main/java/org/apache/struts/validation_messages/ExampleSupport.java b/validation-messages/src/main/java/org/apache/struts/validation_messages/ExampleSupport.java new file mode 100644 index 0000000..ed08c2d --- /dev/null +++ b/validation-messages/src/main/java/org/apache/struts/validation_messages/ExampleSupport.java @@ -0,0 +1,6 @@ +package org.apache.struts.validation_messages; + +import com.opensymphony.xwork2.ActionSupport; + +public class ExampleSupport extends ActionSupport { +} diff --git a/validation-messages/src/main/java/org/apache/struts/validation_messages/Login.java b/validation-messages/src/main/java/org/apache/struts/validation_messages/Login.java new file mode 100644 index 0000000..6fec733 --- /dev/null +++ b/validation-messages/src/main/java/org/apache/struts/validation_messages/Login.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.validation_messages; + +import com.opensymphony.xwork2.ActionSupport; + +public class Login extends ExampleSupport { + + public String execute() { + + if (isInvalid(getUsername())) return INPUT; + + if (isInvalid(getPassword())) return INPUT; + + return SUCCESS; + } + + private boolean isInvalid(String value) { + return (value == null || value.length() == 0); + } + + private String username; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + private String password; + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} \ No newline at end of file diff --git a/validation-messages/src/main/resources/log4j2.xml b/validation-messages/src/main/resources/log4j2.xml new file mode 100644 index 0000000..9160e24 --- /dev/null +++ b/validation-messages/src/main/resources/log4j2.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + <Logger name="com.opensymphony.xwork2" level="info"/> + <Logger name="org.apache.struts2" level="info"/> + <Logger name="org.apache.struts" level="debug"/> + <Root level="warn"> + <AppenderRef ref="STDOUT"/> + </Root> + </Loggers> +</Configuration> \ No newline at end of file diff --git a/validation-messages/src/main/resources/org/apache/struts/validation_messages/Login-validation.xml b/validation-messages/src/main/resources/org/apache/struts/validation_messages/Login-validation.xml new file mode 100644 index 0000000..b923d3d --- /dev/null +++ b/validation-messages/src/main/resources/org/apache/struts/validation_messages/Login-validation.xml @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<!DOCTYPE validators PUBLIC + "-//Apache Struts//XWork Validator 1.0.3//EN" + "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> +<validators> + <field name="username"> + <field-validator type="requiredstring"> + <message key="requiredstring"> + <param name="0">getText('username')</param> + </message> + </field-validator> + </field> + + <field name="password"> + <field-validator type="requiredstring"> + <message key="requiredstring"> + <param name="0">getText('password')</param> + </message> + </field-validator> + </field> +</validators> diff --git a/validation-messages/src/main/resources/org/apache/struts/validation_messages/package.properties b/validation-messages/src/main/resources/org/apache/struts/validation_messages/package.properties new file mode 100644 index 0000000..2fb4f5a --- /dev/null +++ b/validation-messages/src/main/resources/org/apache/struts/validation_messages/package.properties @@ -0,0 +1,4 @@ +requiredstring={0} is required. +password= Password +username=User Name +Missing.message=This feature is under construction. Please try again in the next iteration. diff --git a/validation-messages/src/main/resources/org/apache/struts/validation_messages/package_es.properties b/validation-messages/src/main/resources/org/apache/struts/validation_messages/package_es.properties new file mode 100644 index 0000000..c0336dd --- /dev/null +++ b/validation-messages/src/main/resources/org/apache/struts/validation_messages/package_es.properties @@ -0,0 +1,4 @@ +requiredstring={0} es requerido. +password=Contrase\u00F1a +username=Nombre de Usuario +Missing.message=P\u00E1gina bajo construcci\u00F3n, trate de nuevo en la proxima versi\u00F3n. diff --git a/validation-messages/src/main/resources/struts.xml b/validation-messages/src/main/resources/struts.xml new file mode 100644 index 0000000..866fe83 --- /dev/null +++ b/validation-messages/src/main/resources/struts.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" + "http://struts.apache.org/dtds/struts-2.5.dtd"> +<struts> + <constant name="struts.enable.DynamicMethodInvocation" value="false"/> + <constant name="struts.devMode" value="true"/> + + <include file="example.xml"/> + + <package name="default" namespace="/" extends="struts-default"> + + <default-action-ref name="index"/> + <default-class-ref class="org.apache.struts.validation_messages.ExampleSupport"/> + + <action name="index"> + <result type="redirectAction"> + <param name="actionName">Login</param> + </result> + </action> + + <action name="Login_*" method="{1}" class="org.apache.struts.validation_messages.Login"> + <result name="input">/WEB-INF/Login.jsp</result> + <result type="redirectAction">Menu</result> + </action> + + <action name="Menu"> + <result>/WEB-INF/Menu.jsp</result> + </action> + + </package> + + <!-- Add addition packages and configuration here. --> +</struts> diff --git a/validation-messages/src/main/webapp/WEB-INF/Login.jsp b/validation-messages/src/main/webapp/WEB-INF/Login.jsp new file mode 100644 index 0000000..6438080 --- /dev/null +++ b/validation-messages/src/main/webapp/WEB-INF/Login.jsp @@ -0,0 +1,15 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<html> +<head> + <title>Sign On</title> +</head> + +<body> +<s:form action="Login"> + <s:textfield key="username"/> + <s:password key="password" /> + <s:submit/> +</s:form> +</body> +</html> diff --git a/validation-messages/src/main/webapp/WEB-INF/Menu.jsp b/validation-messages/src/main/webapp/WEB-INF/Menu.jsp new file mode 100644 index 0000000..a74bd2c --- /dev/null +++ b/validation-messages/src/main/webapp/WEB-INF/Menu.jsp @@ -0,0 +1,3 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<s:include value="Missing.jsp"/> \ No newline at end of file diff --git a/validation-messages/src/main/webapp/WEB-INF/Missing.jsp b/validation-messages/src/main/webapp/WEB-INF/Missing.jsp new file mode 100644 index 0000000..7c01ac9 --- /dev/null +++ b/validation-messages/src/main/webapp/WEB-INF/Missing.jsp @@ -0,0 +1,11 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<html> +<head><title>Missing Feature</title></head> + +<body> +<p> + <s:text name="Missing.message"/> +</p> +</body> +</html> diff --git a/validation-messages/src/main/webapp/WEB-INF/web.xml b/validation-messages/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..8858656 --- /dev/null +++ b/validation-messages/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="struts_blank" version="2.4" + xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <display-name>Struts Blank</display-name> + + <filter> + <filter-name>struts2</filter-name> + <filter-class> + org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter + </filter-class> + </filter> + + <filter-mapping> + <filter-name>struts2</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <welcome-file-list> + <welcome-file>index.html</welcome-file> + </welcome-file-list> +</web-app> diff --git a/validation-messages/src/main/webapp/index.html b/validation-messages/src/main/webapp/index.html new file mode 100644 index 0000000..37c44cf --- /dev/null +++ b/validation-messages/src/main/webapp/index.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head> + <META HTTP-EQUIV="Refresh" CONTENT="0;URL=Login.action"> +</head> + +<body> +<p>Loading ...</p> +</body> +</html> -- To stop receiving notification emails like this one, please contact lukaszlen...@apache.org.