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
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,6 +28,7 @@ public BigDecimal getBigDecimal() {
return bigDecimal;
}

@StrutsParameter
public void setBigDecimal(BigDecimal bigDecimal) {
this.bigDecimal = bigDecimal;
}
Expand All @@ -35,6 +37,7 @@ public Double getBigDouble() {
return bigDouble;
}

@StrutsParameter
public void setBigDouble(Double bigDouble) {
this.bigDouble = bigDouble;
}
Expand All @@ -43,6 +46,7 @@ public double getPrimitiveDouble() {
return primitiveDouble;
}

@StrutsParameter
public void setPrimitiveDouble(double primitiveDouble) {
this.primitiveDouble = primitiveDouble;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,23 +34,25 @@ public class ThemeAction extends ActionSupport {
private static final Logger LOG = LogManager.getLogger(ThemeAction.class);

private Map<String, ThemeDescriptor> 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<String, ThemeDescriptor> getThemes() {
return themes;
}

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;
}
}
10 changes: 4 additions & 6 deletions type-conversion/src/main/resources/example.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"https://struts.apache.org/dtds/struts-2.5.dtd">
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
"https://struts.apache.org/dtds/struts-6.0.dtd">
<!--
- This file is included by the struts.xml file as an example
- of how to break up the configuration file into multiple files.
-->
<struts>
<package name="example" namespace="/example" extends="struts-default">

<default-action-ref name="Theme" />

<action name="Theme" class="org.apache.struts.example.ThemeAction">
<result>/WEB-INF/example/Theme.jsp</result>
<result name="input">/WEB-INF/example/Theme.jsp</result>
</action>

<action name="Number" class="org.apache.struts.example.IndexAction">
<action name="Number" class="org.apache.struts.example.NumberAction">
<result name="input">/WEB-INF/example/Number.jsp</result>
</action>

</package>
</struts>
2 changes: 1 addition & 1 deletion type-conversion/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
<PatternLayout pattern="[%-5p] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invalid.fieldvalue.bigDecimal=Wrong value for BigDecimal!
8 changes: 6 additions & 2 deletions type-conversion/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"https://struts.apache.org/dtds/struts-2.5.dtd">
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
"https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"/>
<constant name="struts.devMode" value="true"/>
<constant name="struts.i18n.reload" value="true"/>

<constant name="struts.ui.theme" value="simple"/>

<constant name="struts.allowlist.packageNames" value="org.apache.struts.model"/>

<include file="example.xml"/>

<package name="default" namespace="/" extends="struts-default">
Expand Down
3 changes: 3 additions & 0 deletions type-conversion/src/main/webapp/WEB-INF/example/Number.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
<tr>
<td>BigDecimal</td>
<td><s:textfield name="bigDecimal"/></td>
<td><s:fielderror fieldName="bigDecimal"/></td>
</tr>
<tr>
<td>Double</td>
<td><s:textfield name="bigDouble"/></td>
<td><s:fielderror fieldName="bigDouble"/></td>
</tr>
<tr>
<td>double</td>
<td><s:textfield name="primitiveDouble"/></td>
<td><s:fielderror fieldName="primitiveDouble"/></td>
</tr>
<tr>
<td colspan="2"><s:submit/></td>
Expand Down
4 changes: 3 additions & 1 deletion type-conversion/src/main/webapp/WEB-INF/example/Theme.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
<tr>
<td>Choose</td>
<td><s:select name="selectedTheme" emptyOption="true" list="themes" listKey="value" listValue="value.displayName"/></td>
<td><s:submit/></td>
<td><s:fielderror fieldName="selectedTheme"/></td>
</tr>
<tr>
<td colspan="3"><s:submit/></td>
</table>
</s:form>

Expand Down
Loading