Results 1 to 3 of 3

Thread: Date Property Editors

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Whitehorse, YT, Canada
    Posts
    26

    Default Date Property Editors

    I have a form with two date fields: one has a date and time, and the other is just a date. What is the best way to create a PropertyEditorSupport class so that I can handle both situations as they both are represented as java.util.Date?

    I started by creating such a class and to override the setAsText method, which works perfectly. However, if I don't override getAsText, then I get the full timestamp. And this is where my dilemma begins ... if one is a date and time, and the other is just a date, how can I output them to be displayed differently?

    I do have a kludge which does work, but now I'm testing logic inside a view instead of keeping it in my business class. On overriding getAsText, I check of the date has an hour greater than zero (which works because I'm only dealing with regular office hours).

    Thanks,
    smv

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

    Default

    While registering the property editor using registerCustomEditor on the ServletRequestDataBinder you can also specify a field name. Use that in combination with a somewhat configurable property editor (for example mention a boolean in the constructor indicating whether or not to also output timestamps).

    binder.registerCustomEditor(Date.class, "timestamp", new MyDateEditor(true));
    binder.registerCustomEditor(Date.class, "noTimestamp", new MyDateEditor(false));

    Hope this helps,

    Alef

  3. #3
    Join Date
    Aug 2004
    Location
    Whitehorse, YT, Canada
    Posts
    26

    Default

    Thank you, that works perfectly! I wasn't aware that I could pass a field name along with the registering the property editor. So, I'm now using the built-in CustomDateEditor instead of rolling my own editor.

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  5. Replies: 2
    Last Post: May 13th, 2005, 05:42 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
  •