Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-1777

DateTimePicker doesn't support expressions in the property "displayFormat" - WITH SOLUTION

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.6
    • 2.0.7
    • Plugin - Tags
    • 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)

      { throw (new ParseException("Something is REALLY WRONG!!!! the displayFormat is being used BEFORE EVALUATION!!!",0)); }

      SimpleDateFormat format = new SimpleDateFormat(
      disF.toString());

      Attachments

        1. patch.txt
          1.0 kB
          Alexander Picoli

        Activity

          People

            musachy Musachy Barroso
            abmpicoli Alexander Picoli
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: