diff --git a/type-conversion/src/main/java/org/apache/struts/example/NumberAction.java b/type-conversion/src/main/java/org/apache/struts/example/NumberAction.java index 32a78b44..16653cb5 100644 --- a/type-conversion/src/main/java/org/apache/struts/example/NumberAction.java +++ b/type-conversion/src/main/java/org/apache/struts/example/NumberAction.java @@ -3,6 +3,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; import java.math.BigDecimal; @@ -27,6 +28,7 @@ public BigDecimal getBigDecimal() { return bigDecimal; } + @StrutsParameter public void setBigDecimal(BigDecimal bigDecimal) { this.bigDecimal = bigDecimal; } @@ -35,6 +37,7 @@ public Double getBigDouble() { return bigDouble; } + @StrutsParameter public void setBigDouble(Double bigDouble) { this.bigDouble = bigDouble; } @@ -43,6 +46,7 @@ public double getPrimitiveDouble() { return primitiveDouble; } + @StrutsParameter public void setPrimitiveDouble(double primitiveDouble) { this.primitiveDouble = primitiveDouble; } diff --git a/type-conversion/src/main/java/org/apache/struts/example/ThemeAction.java b/type-conversion/src/main/java/org/apache/struts/example/ThemeAction.java index 95fb6396..64606dcc 100644 --- a/type-conversion/src/main/java/org/apache/struts/example/ThemeAction.java +++ b/type-conversion/src/main/java/org/apache/struts/example/ThemeAction.java @@ -24,6 +24,8 @@ import org.apache.struts.model.ThemeDescriptor; import org.apache.struts.model.Themes; import org.apache.struts2.ActionSupport; +import org.apache.struts2.interceptor.parameter.StrutsParameter; +import org.apache.struts2.validator.annotations.ConversionErrorFieldValidator; import java.util.Map; @@ -32,10 +34,10 @@ public class ThemeAction extends ActionSupport { private static final Logger LOG = LogManager.getLogger(ThemeAction.class); private Map themes = Themes.list(); - private ThemeDescriptor selectedTheme = Themes.get("simple"); + private ThemeDescriptor selectedTheme;// = Themes.get("simple"); public String execute() throws Exception { - return SUCCESS; + return INPUT; } public Map getThemes() { @@ -43,12 +45,14 @@ public Map getThemes() { } public ThemeDescriptor getSelectedTheme() { - LOG.info("Existing theme: #0", String.valueOf(selectedTheme)); + LOG.info("Existing theme: {}", String.valueOf(selectedTheme)); return selectedTheme; } + @StrutsParameter + @ConversionErrorFieldValidator(fieldName = "selectedTheme", key = "error.theme.not.valid", message = "Invalid theme") public void setSelectedTheme(ThemeDescriptor selectedTheme) { - LOG.info("Selected theme: #0", String.valueOf(selectedTheme)); + LOG.info("Selected theme: {}", String.valueOf(selectedTheme)); this.selectedTheme = selectedTheme; } } diff --git a/type-conversion/src/main/resources/example.xml b/type-conversion/src/main/resources/example.xml index 5535fe63..a83dbdc8 100644 --- a/type-conversion/src/main/resources/example.xml +++ b/type-conversion/src/main/resources/example.xml @@ -1,23 +1,21 @@ + "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN" + "https://struts.apache.org/dtds/struts-6.0.dtd"> - - /WEB-INF/example/Theme.jsp + /WEB-INF/example/Theme.jsp - + /WEB-INF/example/Number.jsp - diff --git a/type-conversion/src/main/resources/log4j2.xml b/type-conversion/src/main/resources/log4j2.xml index 06f17666..4cf31c06 100644 --- a/type-conversion/src/main/resources/log4j2.xml +++ b/type-conversion/src/main/resources/log4j2.xml @@ -2,7 +2,7 @@ - + diff --git a/type-conversion/src/main/resources/org/apache/struts/example/NumberAction.properties b/type-conversion/src/main/resources/org/apache/struts/example/NumberAction.properties new file mode 100644 index 00000000..0434ee20 --- /dev/null +++ b/type-conversion/src/main/resources/org/apache/struts/example/NumberAction.properties @@ -0,0 +1 @@ +invalid.fieldvalue.bigDecimal=Wrong value for BigDecimal! diff --git a/type-conversion/src/main/resources/xwork-conversion.properties b/type-conversion/src/main/resources/struts-conversion.properties similarity index 100% rename from type-conversion/src/main/resources/xwork-conversion.properties rename to type-conversion/src/main/resources/struts-conversion.properties diff --git a/type-conversion/src/main/resources/struts.xml b/type-conversion/src/main/resources/struts.xml index e1351b45..da892649 100644 --- a/type-conversion/src/main/resources/struts.xml +++ b/type-conversion/src/main/resources/struts.xml @@ -1,12 +1,16 @@ + "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN" + "https://struts.apache.org/dtds/struts-6.0.dtd"> + + + + diff --git a/type-conversion/src/main/webapp/WEB-INF/example/Number.jsp b/type-conversion/src/main/webapp/WEB-INF/example/Number.jsp index bc556c70..066a57cb 100644 --- a/type-conversion/src/main/webapp/WEB-INF/example/Number.jsp +++ b/type-conversion/src/main/webapp/WEB-INF/example/Number.jsp @@ -29,14 +29,17 @@ BigDecimal + Double + double + diff --git a/type-conversion/src/main/webapp/WEB-INF/example/Theme.jsp b/type-conversion/src/main/webapp/WEB-INF/example/Theme.jsp index 4fef193f..b024c7fd 100644 --- a/type-conversion/src/main/webapp/WEB-INF/example/Theme.jsp +++ b/type-conversion/src/main/webapp/WEB-INF/example/Theme.jsp @@ -15,8 +15,10 @@ Choose - + + +