You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2021/12/21 19:28:35 UTC
[struts-examples] branch master updated: Adds simple example with dynamic href
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 d72a704 Adds simple example with dynamic href
d72a704 is described below
commit d72a704596885edf68dc896ac03824873bf1e1f1
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue Dec 21 20:28:16 2021 +0100
Adds simple example with dynamic href
---
dynamic-href/pom.xml | 57 +++++++++++++++++++++
.../org/apache/struts_example/IndexAction.java | 33 ++++++++++++
dynamic-href/src/main/resources/log4j2.xml | 16 ++++++
dynamic-href/src/main/resources/struts.xml | 21 ++++++++
dynamic-href/src/main/webapp/WEB-INF/index.jsp | 20 ++++++++
dynamic-href/src/main/webapp/WEB-INF/web.xml | 23 +++++++++
.../src/main/webapp/images/icon_waste_sml.png | Bin 0 -> 6813 bytes
dynamic-href/src/main/webapp/index.html | 10 ++++
pom.xml | 1 +
type-conversion/src/main/resources/example.xml | 4 +-
10 files changed, 183 insertions(+), 2 deletions(-)
diff --git a/dynamic-href/pom.xml b/dynamic-href/pom.xml
new file mode 100644
index 0000000..4b05020
--- /dev/null
+++ b/dynamic-href/pom.xml
@@ -0,0 +1,57 @@
+<?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.1.0</version>
+ </parent>
+
+ <artifactId>dynamic-href</artifactId>
+ <name>Dynamic Url</name>
+
+ <packaging>war</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <jetty-plugin.version>9.4.35.v20201120</jetty-plugin.version>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <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>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/dynamic-href/src/main/java/org/apache/struts_example/IndexAction.java b/dynamic-href/src/main/java/org/apache/struts_example/IndexAction.java
new file mode 100644
index 0000000..1997d7d
--- /dev/null
+++ b/dynamic-href/src/main/java/org/apache/struts_example/IndexAction.java
@@ -0,0 +1,33 @@
+package org.apache.struts_example;
+
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionSupport;
+
+import java.util.UUID;
+
+public class IndexAction extends ActionSupport {
+
+ private String entityId;
+ private String processId;
+ private String deleteItem;
+
+ @Override
+ public String execute() throws Exception {
+ entityId = UUID.randomUUID().toString();
+ processId = Thread.currentThread().getName();
+ deleteItem = String.format("Entity %s", entityId);
+ return Action.SUCCESS;
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public String getProcessId() {
+ return processId;
+ }
+
+ public String getDeleteItem() {
+ return deleteItem;
+ }
+}
diff --git a/dynamic-href/src/main/resources/log4j2.xml b/dynamic-href/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..3b0e7d8
--- /dev/null
+++ b/dynamic-href/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="[%highlight{%p}] %d [%t] %C{2} (%F:%L) - %m%n"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.opensymphony.xwork2" level="debug"/>
+ <Logger name="org.apache.struts2" level="debug"/>
+ <Logger name="org.apache.struts.example" level="debug"/>
+ <Root level="warn">
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git a/dynamic-href/src/main/resources/struts.xml b/dynamic-href/src/main/resources/struts.xml
new file mode 100644
index 0000000..4ff989c
--- /dev/null
+++ b/dynamic-href/src/main/resources/struts.xml
@@ -0,0 +1,21 @@
+<?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"/>
+ <constant name="struts.i18n.reload" value="true"/>
+
+ <package name="default" extends="struts-default">
+
+ <default-action-ref name="index"/>
+
+ <action name="index" class="org.apache.struts_example.IndexAction">
+ <result>/WEB-INF/index.jsp</result>
+ </action>
+
+ </package>
+
+ <!-- Add addition packages and configuration here. -->
+</struts>
diff --git a/dynamic-href/src/main/webapp/WEB-INF/index.jsp b/dynamic-href/src/main/webapp/WEB-INF/index.jsp
new file mode 100644
index 0000000..ee46b1a
--- /dev/null
+++ b/dynamic-href/src/main/webapp/WEB-INF/index.jsp
@@ -0,0 +1,20 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title>Dynamic url</title>
+</head>
+
+<body>
+
+<s:url var="delUrl" action="delete">
+ <s:param name="id" value="#entityId" />
+</s:url>
+
+<s:a id="id_%{#attr.processId}" href="%{#attr.delUrl}" escapeHtmlBody="false">
+ <img src='<s:url value="/images/icon_waste_sml.png"/>' alt="X" title="<s:property value='#attr.deleteItem' />" />
+</s:a>
+
+</body>
+</html>
diff --git a/dynamic-href/src/main/webapp/WEB-INF/web.xml b/dynamic-href/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5923ee0
--- /dev/null
+++ b/dynamic-href/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app id="struts_dynamic_url" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>Dynamic Url</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/dynamic-href/src/main/webapp/images/icon_waste_sml.png b/dynamic-href/src/main/webapp/images/icon_waste_sml.png
new file mode 100644
index 0000000..113a71c
Binary files /dev/null and b/dynamic-href/src/main/webapp/images/icon_waste_sml.png differ
diff --git a/dynamic-href/src/main/webapp/index.html b/dynamic-href/src/main/webapp/index.html
new file mode 100644
index 0000000..abdee36
--- /dev/null
+++ b/dynamic-href/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=index.action">
+</head>
+
+<body>
+<p>Loading ...</p>
+</body>
+</html>
diff --git a/pom.xml b/pom.xml
index 058de4d..f9615c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,6 +79,7 @@
<module>control-tags</module>
<module>crud</module>
<module>debugging-struts</module>
+ <module>dynamic-href</module>
<module>exception-handling</module>
<module>exclude-parameters</module>
<module>file-upload</module>
diff --git a/type-conversion/src/main/resources/example.xml b/type-conversion/src/main/resources/example.xml
index b12b0a3..ab9c453 100644
--- a/type-conversion/src/main/resources/example.xml
+++ b/type-conversion/src/main/resources/example.xml
@@ -2,7 +2,7 @@
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
-<!--
+<!--
- This file is included by the struts.xml file as an example
- of how to break up the configuration file into multiple files.
-->
@@ -15,7 +15,7 @@
<result>/WEB-INF/example/Theme.jsp</result>
</action>
- <action name="Number" class="org.apache.struts.example.NumberAction">
+ <action name="Number" class="org.apache.struts.example.IndexAction">
<result name="input">/WEB-INF/example/Number.jsp</result>
</action>