Results 1 to 5 of 5

Thread: getAsText not called

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Location
    Porto Alegre, RS, Brazil
    Posts
    14

    Default getAsText not called

    Hello.

    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.

    Mauricio

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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?

    rgds,
    Alef Arendsen
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Apr 2005
    Location
    Porto Alegre, RS, Brazil
    Posts
    14

    Default

    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="format.date" 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.

    Mauricio

  4. #4
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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?

    rgds,
    Alef
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  5. #5
    Join Date
    Apr 2005
    Location
    Porto Alegre, RS, Brazil
    Posts
    14

    Default

    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="format.date" arguments="<%= person.getDateDeactivated() %>"/>

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


    But this one throws that exception:

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

    Neither this:

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

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

    Thanks again.

    Mauricio

Similar Threads

  1. handleInvalidSubmit called, why?
    By sulam in forum Web
    Replies: 9
    Last Post: Feb 2nd, 2007, 03:11 AM
  2. Replies: 6
    Last Post: Nov 30th, 2005, 04:21 AM
  3. Replies: 0
    Last Post: Sep 1st, 2005, 04:19 PM
  4. Replies: 5
    Last Post: Aug 26th, 2005, 09:29 AM
  5. indirectly called method not intercepted
    By springtester in forum AOP
    Replies: 1
    Last Post: Sep 1st, 2004, 06:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •