[ 
https://issues.apache.org/struts/browse/WW-1777?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40331
 ] 

Musachy Barroso commented on WW-1777:
-------------------------------------

Thanks for the patch!

> DateTimePicker doesn't support expressions in the property "displayFormat" - 
> WITH SOLUTION
> ------------------------------------------------------------------------------------------
>
>                 Key: WW-1777
>                 URL: https://issues.apache.org/struts/browse/WW-1777
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Views
>    Affects Versions: 2.0.6
>         Environment: Windows XP machine, Pentium Mobile... 
>            Reporter: Alexander Picoli
>         Assigned To: Musachy Barroso
>            Priority: Minor
>             Fix For: 2.0.7
>
>         Attachments: patch.txt
>
>
> >>>>> 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)
>                   {
>                       throw (new ParseException("Something is REALLY 
> WRONG!!!! the displayFormat is being used BEFORE EVALUATION!!!",0));
>                   }
>                     SimpleDateFormat format = new SimpleDateFormat(
>                             disF.toString());
>   

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to