Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.0.6
-
None
-
Windows XP machine, Pentium Mobile...
Description
>>>>> Here's "the bomb": <<<<<
I have a JSP snippet that looks like this:
<s:datetimepicker name="dataIni.date" value="%
{dataIni.dateRFC}" displayFormat="%
{getText('dateFormat')}"/>
>>>>> Here's "the BOOOM!" <<<<<
This "snippet" doesn't get rendered at all. Instead, at the application log, I get this:
ERROR:15:05:54,287; class: org.apache.catalina.core.StandardWrapperValve; method:invoke -(lin. 253):Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: Illegal pattern character 'g'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:678)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:497)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:446)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:427)
at org.apache.struts2.components.DateTimePicker.format(DateTimePicker.java:305)
...
>>>>> Here's the diagnosis: <<<<<
In the org.apache.struts2.components.DateTimePicker
component, the
private String format(Object obj) {
method has the following code snippet:
Date date = null;
if(this.displayFormat != null) {
SimpleDateFormat format = new SimpleDateFormat(
this.displayFormat);
date = format.parse(dateStr);
The problem with this code is that "this.displayFormat" is the "Source Expression", before ognl evaluation, and not the result parameter.
>>>>> The SOLUTION <<<<<
replace the format instanciation with this code snippet, that instead of using the unevaluated value of displayFormat, uses the
EVALUATED value;
Object disF = this.getParameters().get("displayFormat");
if(disF == null)
SimpleDateFormat format = new SimpleDateFormat(
disF.toString());