Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
43 changes: 43 additions & 0 deletions struts-parameter/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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 + '\'' +
'}';
}
}
15 changes: 15 additions & 0 deletions struts-parameter/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -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>
20 changes: 20 additions & 0 deletions struts-parameter/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
@@ -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>
18 changes: 18 additions & 0 deletions struts-parameter/src/main/webapp/WEB-INF/examples/index.jsp
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions struts-parameter/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions struts-parameter/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% response.sendRedirect("index"); %>
Loading