4 Replies Latest reply on Dec 11, 2007 11:25 AM by mars1412

    JBoss EL date formatting

    manuel.martin

      Supose that I got a localized message like that

      message = My date is #{myDate}

      and myDate is a session Date var.

      When I print the message #{messages['message']} I got the next output:

      My date is 2007-11-27 12:22:46.338

      Is there any method to format the output of the date? I would like obtain

      My date is 2007-11-27.

      Thanks in advance!

        • 1. Re: JBoss EL date formatting
          damianharvey

          There are a plethora of options open to you here.

          1. If the messages.properties message is just 'My date is'. Then you just print out your date eg:

          #{messages['message']}<h:outputText value="#{myDate}"><s:convertDateTime dateStyle="yyyy-MM-dd"/></h:outputText>


          2. If the messages.properties message is 'My Date is {0}' then you could create the message in your Bean using MessageFormat eg:
          @In Map<String, String> messages;
          ..
          public String getMyMessage() {
           return MessageFormat.format(messages.get("message"), new SimpleDateFormat("yyyy-MM-dd").format(this.myDate));
          }

          I'm sure that there are several other ways of doing it.

          Cheers,

          Damian.

          • 2. Re: JBoss EL date formatting
            manuel.martin

            Thank you Damian, I discard Option 1 because:

            Maybe in other languages the phrase may be writen with another words order. EJ:

            #{myDate} is the date


            But option 2 is useful for me:

            My date is {0,date,dd-MM-yyyy}


            But, do you know if I can pass these parameters throug EL? Ej:

            #{messages['message'](myDate)}


            or something like these?

            Thanks!

            • 3. Re: JBoss EL date formatting
              damianharvey

              Don't think that you can. It's a Map so doesn't have that ability. It shouldn't be too difficult to write your own MessageFormat type component though.

              Cheers,

              Damian.

              • 4. Re: JBoss EL date formatting