Skip to content

Commit df87211

Browse files
authored
Merge pull request #447 from fp024/dev-2025-04-17-a
Refactor(some examples): Update for Struts 7 compatibility
2 parents e15043f + 8f9b568 commit df87211

62 files changed

Lines changed: 195 additions & 123 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

exclude-parameters/src/main/java/org/apache/struts/edit/action/EditAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.apache.struts.edit.service.EditServiceInMemory;
1111
import org.apache.struts2.ActionSupport;
1212
import org.apache.struts2.Preparable;
13+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
1314

1415
import java.util.ArrayList;
1516
import java.util.Arrays;
@@ -61,6 +62,7 @@ public String input() throws Exception {
6162
return INPUT;
6263
}
6364

65+
@StrutsParameter(depth = 1)
6466
public Person getPersonBean() {
6567
return personBean;
6668
}

exclude-parameters/src/main/resources/struts.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<struts>
77

88
<constant name="struts.devMode" value="true" />
9-
9+
<constant name="struts.allowlist.packageNames" value="org.apache.struts.edit.model" />
1010
<package name="basicstruts2" extends="struts-default" >
1111

1212
<interceptors>
@@ -20,7 +20,7 @@
2020
</interceptors>
2121

2222
<default-interceptor-ref name="appDefault" />
23-
23+
<default-action-ref name="index" />
2424
<!-- If no class attribute is specified the framework will assume success and
2525
render the result index.jsp -->
2626
<!-- If no name value for the result node is specified the success value is the default -->

exclude-parameters/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app id="WebApp_ID" 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">
2+
<web-app id="WebApp_ID" version="6.0"
3+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
36
<display-name>Exclude Parameters</display-name>
47
<welcome-file-list>
58
<welcome-file>index.jsp</welcome-file>

form-processing/src/main/java/org/apache/struts/helloworld/action/HelloWorldAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.struts.helloworld.model.MessageStore;
44
import org.apache.struts2.ActionSupport;
5+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
56

67
/**
78
* Acts as a Struts 2 controller that responds
@@ -37,6 +38,7 @@ public String getUserName() {
3738
return userName;
3839
}
3940

41+
@StrutsParameter
4042
public void setUserName(String userName) {
4143
this.userName = userName;
4244
}

form-processing/src/main/java/org/apache/struts/register/action/Register.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import org.apache.struts.register.model.Person;
44
import org.apache.struts2.ActionSupport;
5+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
56

6-
import java.util.ArrayList;
77
import java.util.List;
88

99
public class Register extends ActionSupport {
@@ -17,15 +17,10 @@ public String execute2() throws Exception {
1717
}
1818

1919
public String input() throws Exception {
20-
this.options = new ArrayList<>();
21-
this.options.add(3);
2220
return INPUT;
2321
}
2422

25-
public String cancel2() throws Exception {
26-
return SUCCESS;
27-
}
28-
23+
@StrutsParameter(depth = 1)
2924
public Person getPersonBean() {
3025
return personBean;
3126
}
@@ -34,6 +29,7 @@ public void setPersonBean(Person person) {
3429
personBean = person;
3530
}
3631

32+
@StrutsParameter(depth = 1)
3733
public List<Integer> getOptions() {
3834
return options;
3935
}

form-processing/src/main/resources/struts.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<constant name="struts.devMode" value="true" />
77
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
88
<constant name="struts.mapper.action.prefix.enabled" value="true"/>
9+
<constant name="struts.allowlist.classes" value="org.apache.struts.helloworld.model.MessageStore"/>
910

1011
<package name="basicstruts" namespace="/" extends="struts-default">
1112
<default-action-ref name="index"/>
@@ -33,7 +34,7 @@
3334
<action name="register" class="org.apache.struts.register.action.Register" method="input">
3435
<result name="input">/WEB-INF/register.jsp</result>
3536
</action>
36-
<action name="register-cancel" class="org.apache.struts.register.action.Register" method="cancel2">
37+
<action name="register-cancel">
3738
<result type="redirectAction">index</result>
3839
</action>
3940
<action name="register-submit" class="org.apache.struts.register.action.Register" method="execute2">

form-processing/src/main/webapp/WEB-INF/index.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
<s:submit value="Submit" />
2121
</s:form>
2222

23-
<p><a href="register">Please register</a> for our prize drawing.</p>
23+
<p><a href="<s:url action='register'/>">Please register</a> for our prize drawing.</p>
2424
</body>
2525
</html>

form-processing/src/main/webapp/WEB-INF/register.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body>
1010
<h3>Register for a prize by completing this form.</h3>
1111

12-
<s:form action="register-submit" namespace="test">
12+
<s:form action="register-submit" namespace="/test">
1313
<s:textfield name="personBean.firstName" label="First name"/>
1414
<s:textfield name="personBean.lastName" label="Last name"/>
1515
<s:textfield name="personBean.email" label="Email"/>

form-processing/src/main/webapp/WEB-INF/web.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
2+
<web-app id="WebApp_ID" version="6.0"
3+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd">
56
<display-name>Form_Processing_Struts2_Mvn</display-name>
67

78
<filter>

form-tags/src/main/java/org/apache/struts/edit/action/EditAction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.apache.struts.edit.service.EditService;
66
import org.apache.struts.edit.service.EditServiceInMemory;
77
import org.apache.struts2.ActionSupport;
8+
import org.apache.struts2.interceptor.parameter.StrutsParameter;
89

910
import java.util.ArrayList;
1011
import java.util.Arrays;
@@ -36,6 +37,7 @@ public String input() throws Exception {
3637
return INPUT;
3738
}
3839

40+
@StrutsParameter(depth = 1)
3941
public Person getPersonBean() {
4042
return personBean;
4143
}

0 commit comments

Comments
 (0)