This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch struts-parameter
in repository https://gitbox.apache.org/repos/asf/struts-examples.git

commit bf344d616ac83db245dceb38f824d890783ad83b
Author: Lukasz Lenart <[email protected]>
AuthorDate: Wed Jun 17 09:15:53 2026 +0200

    Defines a new struts-parameter example app to show how @StrutsParameter 
works
---
 pom.xml                                            |  1 +
 struts-parameter/pom.xml                           | 43 ++++++++++++++++
 .../apache/struts/examples/parameter/Admin.java    | 27 ++++++++++
 .../struts/examples/parameter/IndexAction.java     | 57 ++++++++++++++++++++++
 .../org/apache/struts/examples/parameter/User.java | 39 +++++++++++++++
 struts-parameter/src/main/resources/log4j2.xml     | 15 ++++++
 struts-parameter/src/main/resources/struts.xml     | 20 ++++++++
 .../src/main/webapp/WEB-INF/examples/index.jsp     | 18 +++++++
 struts-parameter/src/main/webapp/WEB-INF/web.xml   | 21 ++++++++
 struts-parameter/src/main/webapp/index.jsp         |  1 +
 10 files changed, 242 insertions(+)

diff --git a/pom.xml b/pom.xml
index 5129b5d..60e3c93 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,6 +110,7 @@
         <module>rest-angular</module>
         <module>shiro-basic</module>
         <module>spring-struts</module>
+        <module>struts-parameter</module>
         <module>text-provider</module>
         <module>tiles</module>
         <module>themes</module>
diff --git a/struts-parameter/pom.xml b/struts-parameter/pom.xml
new file mode 100644
index 0000000..8765987
--- /dev/null
+++ b/struts-parameter/pom.xml
@@ -0,0 +1,43 @@
+<?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>2.0.0</version>
+    </parent>
+    
+    <artifactId>struts-parameter</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <packaging>war</packaging>
+    <name>struts-parameter</name>
+    <description>A simple application demonstrating how to use 
@StrutsParameter annotation</description>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+    </properties>
+
+    <dependencies/>
+
+    <build>
+        <finalName>annotations</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>
+                    <scan>10</scan>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
diff --git 
a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java
 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java
new file mode 100644
index 0000000..09644d7
--- /dev/null
+++ 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/Admin.java
@@ -0,0 +1,27 @@
+package org.apache.struts.examples.parameter;
+
+public class Admin {
+    private String username;
+
+    public Admin() {
+    }
+
+    public Admin(String username) {
+        this.username = username;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public void setUsername(String username) {
+        this.username = username;
+    }
+
+    @Override
+    public String toString() {
+        return "Admin{" +
+                "username='" + username + '\'' +
+                '}';
+    }
+}
diff --git 
a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java
 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java
new file mode 100644
index 0000000..b92da32
--- /dev/null
+++ 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/IndexAction.java
@@ -0,0 +1,57 @@
+/*
+ * 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.examples.parameter;
+
+import org.apache.struts2.ActionSupport;
+import org.apache.struts2.interceptor.parameter.StrutsParameter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class IndexAction extends ActionSupport {
+
+    private final List<User> users = new ArrayList<>();
+    private Admin admin;
+    
+    public String execute() throws Exception {
+        if (users.isEmpty()) {
+            users.add(new User(1, "Luk"));
+            users.add(new User(2, "Jan"));
+        }
+        if (admin == null) {
+            admin = new Admin("Michal");
+        }
+        return SUCCESS;
+    }
+
+    @StrutsParameter(depth = 2)
+    public List<User> getUsers() {
+        return users;
+    }
+
+    @StrutsParameter(depth = 2)
+    public Admin getAdminUser() {
+        return admin;
+    }
+
+    @StrutsParameter(depth = 2)
+    public void setAdminUser(Admin admin) {
+        this.admin = admin;
+    }
+}
\ No newline at end of file
diff --git 
a/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java
new file mode 100644
index 0000000..e50d1ad
--- /dev/null
+++ 
b/struts-parameter/src/main/java/org/apache/struts/examples/parameter/User.java
@@ -0,0 +1,39 @@
+package org.apache.struts.examples.parameter;
+
+public class User {
+    
+    private int id;
+    private String name;
+
+    public User() {
+    }
+
+    public User(int id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public String toString() {
+        return "User{" +
+                "id=" + id +
+                ", name='" + name + '\'' +
+                '}';
+    }
+}
diff --git a/struts-parameter/src/main/resources/log4j2.xml 
b/struts-parameter/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..32cbd7e
--- /dev/null
+++ b/struts-parameter/src/main/resources/log4j2.xml
@@ -0,0 +1,15 @@
+<?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="org.apache.struts2.conversion" level="debug"/>
+        <Logger name="org.apache.struts.examples.parameter" level="debug"/>
+        <Root level="warn">
+            <AppenderRef ref="STDOUT"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file
diff --git a/struts-parameter/src/main/resources/struts.xml 
b/struts-parameter/src/main/resources/struts.xml
new file mode 100644
index 0000000..d6778c4
--- /dev/null
+++ b/struts-parameter/src/main/resources/struts.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE struts PUBLIC
+        "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+        "http://struts.apache.org/dtds/struts-6.0.dtd";>
+<struts>
+    <constant name="struts.devMode" value="true"/>
+    <constant name="struts.allowlist.packageNames" 
value="org.apache.struts.examples.parameter"/>
+
+    <package name="default" namespace="/" extends="struts-default">
+
+        <default-action-ref name="index"/>
+
+        <action name="index" 
class="org.apache.struts.examples.parameter.IndexAction">
+            <result name="success">/WEB-INF/examples/index.jsp</result>
+        </action>
+
+    </package>
+
+    <!-- Add addition packages and configuration here. -->
+</struts>
diff --git a/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp 
b/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp
new file mode 100644
index 0000000..ccb87a4
--- /dev/null
+++ b/struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp
@@ -0,0 +1,18 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+    <title>Home</title>
+</head>
+
+<body>
+<s:form action="index" method="POST">
+    <s:iterator value="users" status="status">
+        <s:hidden name="users[%{#status.index}].id"/>
+        <s:textfield name="users[%{#status.index}].name" label="User 
%{users[#status.index].id}" id="user_%{users[#status.index].id}"/>
+    </s:iterator>
+    <s:textfield name="adminUser.username" label="Admin"/>
+    <s:submit/>
+</s:form>
+</body>
+</html>
diff --git a/struts-parameter/src/main/webapp/WEB-INF/web.xml 
b/struts-parameter/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7f5eaf9
--- /dev/null
+++ b/struts-parameter/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
+         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd";
+         version="3.1">
+    <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.jsp</welcome-file>
+    </welcome-file-list>
+
+</web-app>
diff --git a/struts-parameter/src/main/webapp/index.jsp 
b/struts-parameter/src/main/webapp/index.jsp
new file mode 100644
index 0000000..d40e6d4
--- /dev/null
+++ b/struts-parameter/src/main/webapp/index.jsp
@@ -0,0 +1 @@
+<% response.sendRedirect("index"); %>

Reply via email to