Announcement Announcement Module
No announcement yet.
getAsText not called Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • getAsText not called


    I made my own Date property editor, but I'm having some problems about that. My "getAsText" method is not being called. "setAsText" works fine.

    Could anybody help me? Why does getAsText could not being called?

    Thanks in advance.


  • #2
    When do you expect getAsText() to be called. This is only called when actually retrtieving the Date object represented as a String (usually in the web-tier). When usign the DateEditor in an AppicationContext, getAsText() will probably never get called (Spring only needs to go from a String to a Date and not the other way around - in which case it would need the getAsText() method).

    Does this help?

    Alef Arendsen


    • #3
      I expected it to be called before the date be shown in my jsp. In my function getAsText, I'd like to acess my resourcebundle, get the date format for that user's locale, and put the timestamp, that I get from the database, on that format.

      I know this conversion can be done in other places. I tried to do that using the spring:message tag, like this:

      <sp:message code="" arguments="${person.dateDeactivated}"/>

      But, as my bean attribute 'dateDeactivated' is a java.util.Date, it was not working, and I was forced to convert it to timestamp using jsp scriplets. And, as our rule here in the company is: "no scriplets. just jstl"...

      That's the reason that made me try to use getAsText. I gave up to use spring:message, and tried this:

      <c:out value="${person.dateDeactivated}"/> ... and thought the bundle and and the formatting could be done in my DatePropertyEditor.

      So... thatīs my problem....

      How can I resolve that? Any sugestion???

      Thanks very much.



      • #4
        The DateEditor will only be called when using spring:bind tags in combination with the editor registered in the initBinder() callback of Spring command or form controllers.

        Where have you regsitered it?



        • #5
          Hi Alef,

          I've registered it in the initBinder() method of my SimpleFormContrloller, and now I've added the spring:bind tags to my jsp. SetAsText is called, but getAsText doesn't.

          But, after reading your reply on the day before yesterday I kind of gave up my idea of using that getAsText method to format the response to my user. Now I'm trying to make that from my jsp, just using the spring:message tag:

          Something very strange is happening. I'm doing the same thing using scriplets and jstl. The code which uses scriplets works fine. The one with jstl throws an exception: java.lang.IllegalArgumentException: Cannot format given Object as a Date

          Here's an example:

          This code below works fine:

          <% PersonVO person = (PersonVO) request.getAttribute("person"); %>

          <sp:message code="" arguments="<%= person.getDateDeactivated() %>"/>

          (In my resource bundle I have the following: = {0,date,MM/dd/yyyy} )

          But this one throws that exception:

          <sp:message code="" arguments="${person.dateDeactivated}"/>

          Neither this:

          <sp:message code="" arguments="<c:out
          value='${person.dateDeactivated}' />"/>

          Am I doing something stupid in these last two codes? Wasn't they supposed to work?

          Thanks again.